I found an issue when testing the double-hashed prefix-lookup DHT; I noticed providers were being returned in the queryFn in findProvidersAsync, but they weren't being entered into the peerOut 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 in query.Run; however since the queryFn 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 the peerOut 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 the peerOut channel, which is what the PR now does (and also fixes the above issue).
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).