eth/downloader: fix cancel channel double close

This commit is contained in:
Péter Szilágyi 2015-05-15 19:43:42 +03:00
parent 7d71a75d77
commit 4f0d88cb02

View File

@ -212,9 +212,14 @@ func (d *Downloader) Cancel() bool {
return false
}
// Close the current cancel channel
d.cancelLock.RLock()
close(d.cancelCh)
d.cancelLock.RUnlock()
d.cancelLock.Lock()
select {
case <-d.cancelCh:
// Channel was already closed
default:
close(d.cancelCh)
}
d.cancelLock.Unlock()
// reset the queue
d.queue.Reset()