mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-25 12:57:17 +00:00
eth/downloader: sync the cancel channel during cancel too
This commit is contained in:
parent
ee0c892303
commit
ec57aa64cd
@ -190,32 +190,15 @@ func (d *Downloader) syncWithPeer(p *peer, hash common.Hash) (err error) {
|
|||||||
// Cancel cancels all of the operations and resets the queue. It returns true
|
// Cancel cancels all of the operations and resets the queue. It returns true
|
||||||
// if the cancel operation was completed.
|
// if the cancel operation was completed.
|
||||||
func (d *Downloader) Cancel() bool {
|
func (d *Downloader) Cancel() bool {
|
||||||
hs, bs := d.queue.Size()
|
|
||||||
// If we're not syncing just return.
|
// If we're not syncing just return.
|
||||||
|
hs, bs := d.queue.Size()
|
||||||
if atomic.LoadInt32(&d.synchronising) == 0 && hs == 0 && bs == 0 {
|
if atomic.LoadInt32(&d.synchronising) == 0 && hs == 0 && bs == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
// Close the current cancel channel
|
||||||
|
d.cancelLock.RLock()
|
||||||
close(d.cancelCh)
|
close(d.cancelCh)
|
||||||
|
d.cancelLock.RUnlock()
|
||||||
// clean up
|
|
||||||
hashDone:
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-d.hashCh:
|
|
||||||
default:
|
|
||||||
break hashDone
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
blockDone:
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-d.blockCh:
|
|
||||||
default:
|
|
||||||
break blockDone
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset the queue
|
// reset the queue
|
||||||
d.queue.Reset()
|
d.queue.Reset()
|
||||||
|
Loading…
Reference in New Issue
Block a user