fix: context cancel causes providers not to be returned in findProvidersAsync
#799
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I found an issue when testing the double-hashed prefix-lookup DHT; I noticed providers were being returned in the
queryFn
infindProvidersAsync
, but they weren't being entered into thepeerOut
channel because the context was cancelled, resulting in no providers being returned.Previously, context being passed to the
queryFn
gets cancelled when the query terminates inquery.Run
; however since thequeryFn
is run in a goroutine (query.go line 325) it's possible for the context passed to it to be cancelled before providers are put into thepeerOut
channel, resulting in no/less providers than expected being returned.It seems to me like the
query.ctx
(which is passed by the user essentially) should be what stops values being put in thepeerOut
channel, which is what the PR now does (and also fixes the above issue).