mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-03-09 04:44:24 +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.
|
||||
// Note: genMarker can be nil even when the generator is still running (waiting
|
||||
// for abort signal after completing generation), so we check genAbort instead.
|
||||
if dl.genAbort != nil {
|
||||
abort := make(chan *generatorStats)
|
||||
dl.genAbort <- abort
|
||||
<-abort
|
||||
//
|
||||
// Use write lock to ensure only one stop can proceed at a time and to safely
|
||||
// clear genAbort after the generator exits.
|
||||
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