Skip to content

Commit

Permalink
Merge pull request #248 from raulk/master
Browse files Browse the repository at this point in the history
Fix a race in dial queue
  • Loading branch information
Stebalien authored Feb 1, 2019
2 parents ebcfcd4 + 94682b4 commit ad151c1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions dial_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit ad151c1

Please sign in to comment.