Commit 1dbefd3f authored by Adin Schmahmann's avatar Adin Schmahmann

fix: lookup context cancellation race condition

parent 3d294c7a
......@@ -117,10 +117,12 @@ func (dht *IpfsDHT) runLookupWithFollowup(ctx context.Context, target string, qu
}
// wait for all queries to complete before returning, aborting ongoing queries if we've been externally stopped
followupsCompleted := 0
processFollowUp:
for i := 0; i < len(queryPeers); i++ {
select {
case <-doneCh:
followupsCompleted++
if stopFn() {
cancelFollowUp()
if i < len(queryPeers)-1 {
......@@ -130,10 +132,17 @@ processFollowUp:
}
case <-ctx.Done():
lookupRes.completed = false
cancelFollowUp()
break processFollowUp
}
}
if !lookupRes.completed {
for i := followupsCompleted; i < len(queryPeers); i++ {
<-doneCh
}
}
return lookupRes, nil
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment