mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-09 22:47:24 +00:00
The race occurred as a result of a goroutine launched by `processPeerUpdate` racing with the `OnStop` method. The `processPeerUpdates` goroutine deletes from the map as `OnStop` is reading from it. This change updates the `OnStop` method to wait for the peer updates channel to be done before closing the peers. It also copies the map contents to a new map so that it will not conflict with the view of the map that the goroutine created in `processPeerUpdate` sees.
This commit is contained in:
@@ -230,17 +230,15 @@ func (r *Reactor) OnStop() {
|
||||
}
|
||||
|
||||
r.mtx.Lock()
|
||||
peers := r.peers
|
||||
// Close and wait for each of the peers to shutdown.
|
||||
// This is safe to perform with the lock since none of the peers require the
|
||||
// lock to complete any of the methods that the waitgroup is waiting on.
|
||||
for _, state := range r.peers {
|
||||
state.closer.Close()
|
||||
state.broadcastWG.Wait()
|
||||
}
|
||||
r.mtx.Unlock()
|
||||
|
||||
// wait for all spawned peer goroutines to gracefully exit
|
||||
for _, ps := range peers {
|
||||
ps.closer.Close()
|
||||
}
|
||||
for _, ps := range peers {
|
||||
ps.broadcastWG.Wait()
|
||||
}
|
||||
|
||||
// Close the StateChannel goroutine separately since it uses its own channel
|
||||
// to signal closure.
|
||||
close(r.stateCloseCh)
|
||||
|
||||
Reference in New Issue
Block a user