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
This commit is contained in:
Aleksandr Bezobchuk
2021-01-25 14:34:55 -05:00
committed by GitHub
parent 13e772c916
commit b3aae970d8

View File

@@ -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: