File tree 1 file changed +12
-5
lines changed
1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ type waitingCh struct {
110
110
// end up adding fuel to the fire. Since we have no deterministic way to detect this for now, we hard-limit concurrency
111
111
// to config.maxParallelism.
112
112
func newDialQueue (params * dqParams ) (* dialQueue , error ) {
113
- sq := & dialQueue {
113
+ dq := & dialQueue {
114
114
dqParams : params ,
115
115
nWorkers : params .config .minParallelism ,
116
116
out : queue .NewChanQueue (params .ctx , queue .NewXORDistancePQ (params .target )),
@@ -121,10 +121,10 @@ func newDialQueue(params *dqParams) (*dialQueue, error) {
121
121
}
122
122
123
123
for i := 0 ; i < int (params .config .minParallelism ); i ++ {
124
- go sq .worker ()
124
+ go dq .worker ()
125
125
}
126
- go sq .control ()
127
- return sq , nil
126
+ go dq .control ()
127
+ return dq , nil
128
128
}
129
129
130
130
func (dq * dialQueue ) control () {
@@ -323,7 +323,14 @@ func (dq *dialQueue) worker() {
323
323
}
324
324
logger .Debugf ("dialling %v took %dms (as observed by the dht subsystem)." , p , time .Since (t )/ time .Millisecond )
325
325
waiting := len (dq .waitingCh )
326
- dq .out .EnqChan <- p
326
+
327
+ // by the time we're done dialling, it's possible that the context is closed, in which case there will
328
+ // be nobody listening on dq.out.EnqChan and we could block forever.
329
+ select {
330
+ case dq .out .EnqChan <- p :
331
+ case <- dq .ctx .Done ():
332
+ return
333
+ }
327
334
if waiting > 0 {
328
335
// we have somebody to deliver this value to, so no need to shrink.
329
336
continue
You can’t perform that action at this time.
0 commit comments