fix a race in dial queue.

This commit is contained in:
Raúl Kripalani
2019-02-01 19:20:32 +00:00
parent ebcfcd46a6
commit 94682b4df2

View File

@@ -208,9 +208,11 @@ func (dq *dialQueue) Consume() <-chan peer.ID {
ch := make(chan peer.ID, 1)
select {
case p := <-dq.out.DeqChan:
// short circuit and return a dialled peer if it's immediately available.
ch <- p
case p, ok := <-dq.out.DeqChan:
// short circuit and return a dialled peer if it's immediately available, or abort if DeqChan is closed.
if ok {
ch <- p
}
close(ch)
return ch
case <-dq.ctx.Done():