From b3aae970d8da74d9d24d16f5dba9a80813fa0cca Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Mon, 25 Jan 2021 14:34:55 -0500 Subject: [PATCH] blockchain v0: fix waitgroup data race (#5970) ## Description Fixes the data race in usage of `WaitGroup`. Specifically, the case where we invoke `Wait` _before_ the first delta `Add` call when the current waitgroup counter is zero. See https://golang.org/pkg/sync/#WaitGroup.Add. Still not sure how this manifests itself in a test since the reactor has to be stopped virtually immediately after being started (I think?). Regardless, this is the appropriate fix. closes: #5968 --- blockchain/v0/reactor.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/blockchain/v0/reactor.go b/blockchain/v0/reactor.go index f055d03b9..7dd4d4ea3 100644 --- a/blockchain/v0/reactor.go +++ b/blockchain/v0/reactor.go @@ -150,6 +150,7 @@ func (r *Reactor) OnStart() error { return err } + r.poolWG.Add(1) go r.poolRoutine(false) } @@ -354,7 +355,9 @@ func (r *Reactor) SwitchToFastSync(state sm.State) error { return err } + r.poolWG.Add(1) go r.poolRoutine(true) + return nil } @@ -426,7 +429,6 @@ func (r *Reactor) poolRoutine(stateSynced bool) { go r.requestRoutine() - r.poolWG.Add(1) defer r.poolWG.Done() FOR_LOOP: