miner: fix data race during shutdown (#23435)

This fixes a data race on worker.current by moving the call to StopPrefetcher
into the main loop.

The commit also contains fixes for two other races in unit tests of unrelated packages.
This commit is contained in:
Marius van der Wijden
2021-10-08 20:12:52 +02:00
committed by GitHub
parent 28d30b51f8
commit ee120ef865
3 changed files with 6 additions and 5 deletions

View File

@ -321,9 +321,6 @@ func (w *worker) isRunning() bool {
// close terminates all background threads maintained by the worker.
// Note the worker does not support being closed multiple times.
func (w *worker) close() {
if w.current != nil && w.current.state != nil {
w.current.state.StopPrefetcher()
}
atomic.StoreInt32(&w.running, 0)
close(w.exitCh)
w.wg.Wait()
@ -455,6 +452,11 @@ func (w *worker) mainLoop() {
defer w.txsSub.Unsubscribe()
defer w.chainHeadSub.Unsubscribe()
defer w.chainSideSub.Unsubscribe()
defer func() {
if w.current != nil && w.current.state != nil {
w.current.state.StopPrefetcher()
}
}()
for {
select {