From 243c62cc68a987095789cae34700235583f24f2d Mon Sep 17 00:00:00 2001 From: William Banfield <4561443+williambanfield@users.noreply.github.com> Date: Fri, 1 Oct 2021 16:33:12 -0400 Subject: [PATCH] statesync: improve rare p2p race condition (#7042) This is intended to fix a test failure that occurs in the p2p state provider. The issue presents as the state provider timing out waiting for the consensus params response. The reason that this can occur is because the statesync reactor has the possibility of attempting to respond to the params request before the state provider is ready to read it. This results in the reactor hitting the `default` case seen here and then never sending on the channel. The stateprovider will then block waiting for a response and never receive one because the reactor opted not to send it. --- internal/statesync/reactor.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/statesync/reactor.go b/internal/statesync/reactor.go index abfa973b5..70b12b7fa 100644 --- a/internal/statesync/reactor.go +++ b/internal/statesync/reactor.go @@ -779,7 +779,8 @@ func (r *Reactor) handleParamsMessage(envelope p2p.Envelope) error { if sp, ok := r.stateProvider.(*stateProviderP2P); ok { select { case sp.paramsRecvCh <- cp: - default: + case <-time.After(time.Second): + return errors.New("failed to send consensus params, stateprovider not ready for response") } } else { r.Logger.Debug("received unexpected params response; using RPC state provider", "peer", envelope.From)