mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
fix: fix multiple abort attempts
This commit is contained in:
parent
1e675e3f85
commit
e06e1355aa
1 changed files with 16 additions and 4 deletions
|
|
@ -193,9 +193,21 @@ func (dl *diskLayer) stopGeneration() {
|
||||||
// Check if generation goroutine is running by checking if genAbort channel exists.
|
// Check if generation goroutine is running by checking if genAbort channel exists.
|
||||||
// Note: genMarker can be nil even when the generator is still running (waiting
|
// Note: genMarker can be nil even when the generator is still running (waiting
|
||||||
// for abort signal after completing generation), so we check genAbort instead.
|
// for abort signal after completing generation), so we check genAbort instead.
|
||||||
if dl.genAbort != nil {
|
//
|
||||||
abort := make(chan *generatorStats)
|
// Use write lock to ensure only one stop can proceed at a time and to safely
|
||||||
dl.genAbort <- abort
|
// clear genAbort after the generator exits.
|
||||||
<-abort
|
dl.lock.Lock()
|
||||||
|
defer dl.lock.Unlock()
|
||||||
|
|
||||||
|
if dl.genAbort == nil {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abort := make(chan *generatorStats)
|
||||||
|
dl.genAbort <- abort
|
||||||
|
<-abort
|
||||||
|
|
||||||
|
// Clear genAbort to prevent subsequent calls from trying to send to a channel
|
||||||
|
// that no longer has a listener, which would block forever.
|
||||||
|
dl.genAbort = nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue