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 ...@@ -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 // wait for all queries to complete before returning, aborting ongoing queries if we've been externally stopped
followupsCompleted := 0
processFollowUp: processFollowUp:
for i := 0; i < len(queryPeers); i++ { for i := 0; i < len(queryPeers); i++ {
select { select {
case <-doneCh: case <-doneCh:
followupsCompleted++
if stopFn() { if stopFn() {
cancelFollowUp() cancelFollowUp()
if i < len(queryPeers)-1 { if i < len(queryPeers)-1 {
...@@ -130,10 +132,17 @@ processFollowUp: ...@@ -130,10 +132,17 @@ processFollowUp:
} }
case <-ctx.Done(): case <-ctx.Done():
lookupRes.completed = false lookupRes.completed = false
cancelFollowUp()
break processFollowUp break processFollowUp
} }
} }
if !lookupRes.completed {
for i := followupsCompleted; i < len(queryPeers); i++ {
<-doneCh
}
}
return lookupRes, nil 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