Skip to content

Commit ec57aa6

Browse files
committed
eth/downloader: sync the cancel channel during cancel too
1 parent ee0c892 commit ec57aa6

1 file changed

Lines changed: 4 additions & 21 deletions

File tree

‎eth/downloader/downloader.go‎

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -190,32 +190,15 @@ func (d *Downloader) syncWithPeer(p *peer, hash common.Hash) (err error) {
190190
// Cancel cancels all of the operations and resets the queue. It returns true
191191
// if the cancel operation was completed.
192192
func (d *Downloader) Cancel() bool {
193-
hs, bs := d.queue.Size()
194193
// If we're not syncing just return.
194+
hs, bs := d.queue.Size()
195195
if atomic.LoadInt32(&d.synchronising) == 0 && hs == 0 && bs == 0 {
196196
return false
197197
}
198-
198+
// Close the current cancel channel
199+
d.cancelLock.RLock()
199200
close(d.cancelCh)
200-
201-
// clean up
202-
hashDone:
203-
for {
204-
select {
205-
case <-d.hashCh:
206-
default:
207-
break hashDone
208-
}
209-
}
210-
211-
blockDone:
212-
for {
213-
select {
214-
case <-d.blockCh:
215-
default:
216-
break blockDone
217-
}
218-
}
201+
d.cancelLock.RUnlock()
219202

220203
// reset the queue
221204
d.queue.Reset()

0 commit comments

Comments
 (0)