forked from cerc-io/plugeth
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:
parent
28d30b51f8
commit
ee120ef865
@ -151,7 +151,7 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, pending bool) *testBacke
|
|||||||
// Construct testing chain
|
// Construct testing chain
|
||||||
diskdb := rawdb.NewMemoryDatabase()
|
diskdb := rawdb.NewMemoryDatabase()
|
||||||
gspec.Commit(diskdb)
|
gspec.Commit(diskdb)
|
||||||
chain, err := core.NewBlockChain(diskdb, nil, gspec.Config, engine, vm.Config{}, nil, nil)
|
chain, err := core.NewBlockChain(diskdb, &core.CacheConfig{TrieCleanNoPrefetch: true}, gspec.Config, engine, vm.Config{}, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create local chain, %v", err)
|
t.Fatalf("Failed to create local chain, %v", err)
|
||||||
}
|
}
|
||||||
|
@ -486,7 +486,6 @@ func TestCheckpointChallenge(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testCheckpointChallenge(t *testing.T, syncmode downloader.SyncMode, checkpoint bool, timeout bool, empty bool, match bool, drop bool) {
|
func testCheckpointChallenge(t *testing.T, syncmode downloader.SyncMode, checkpoint bool, timeout bool, empty bool, match bool, drop bool) {
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
// Reduce the checkpoint handshake challenge timeout
|
// Reduce the checkpoint handshake challenge timeout
|
||||||
defer func(old time.Duration) { syncChallengeTimeout = old }(syncChallengeTimeout)
|
defer func(old time.Duration) { syncChallengeTimeout = old }(syncChallengeTimeout)
|
||||||
|
@ -321,9 +321,6 @@ func (w *worker) isRunning() bool {
|
|||||||
// close terminates all background threads maintained by the worker.
|
// close terminates all background threads maintained by the worker.
|
||||||
// Note the worker does not support being closed multiple times.
|
// Note the worker does not support being closed multiple times.
|
||||||
func (w *worker) close() {
|
func (w *worker) close() {
|
||||||
if w.current != nil && w.current.state != nil {
|
|
||||||
w.current.state.StopPrefetcher()
|
|
||||||
}
|
|
||||||
atomic.StoreInt32(&w.running, 0)
|
atomic.StoreInt32(&w.running, 0)
|
||||||
close(w.exitCh)
|
close(w.exitCh)
|
||||||
w.wg.Wait()
|
w.wg.Wait()
|
||||||
@ -455,6 +452,11 @@ func (w *worker) mainLoop() {
|
|||||||
defer w.txsSub.Unsubscribe()
|
defer w.txsSub.Unsubscribe()
|
||||||
defer w.chainHeadSub.Unsubscribe()
|
defer w.chainHeadSub.Unsubscribe()
|
||||||
defer w.chainSideSub.Unsubscribe()
|
defer w.chainSideSub.Unsubscribe()
|
||||||
|
defer func() {
|
||||||
|
if w.current != nil && w.current.state != nil {
|
||||||
|
w.current.state.StopPrefetcher()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
Loading…
Reference in New Issue
Block a user