eth/downloader: fix downloader cancel

This commit is contained in:
Gary Rong 2025-06-26 13:02:42 +08:00
parent a92f2b86e3
commit fddc8437c0

View file

@ -630,15 +630,18 @@ func (d *Downloader) cancel() {
// Cancel aborts all of the operations and waits for all download goroutines to // Cancel aborts all of the operations and waits for all download goroutines to
// finish before returning. // finish before returning.
func (d *Downloader) Cancel() { func (d *Downloader) Cancel() {
d.blockchain.InterruptInsert(true)
d.cancel() d.cancel()
d.cancelWg.Wait() d.cancelWg.Wait()
d.blockchain.InterruptInsert(false)
} }
// Terminate interrupts the downloader, canceling all pending operations. // Terminate interrupts the downloader, canceling all pending operations.
// The downloader cannot be reused after calling Terminate. // The downloader cannot be reused after calling Terminate.
func (d *Downloader) Terminate() { func (d *Downloader) Terminate() {
// Terminates chain insertion, which may result in an "aborted" error in
// the blockchain and ultimately lead to the corresponding peer being
// disconnected. This is acceptable behavior during Geth shutdown.
d.blockchain.InterruptInsert(true)
// Close the termination channel (make sure double close is allowed) // Close the termination channel (make sure double close is allowed)
d.quitLock.Lock() d.quitLock.Lock()
select { select {