Commit 159785fb authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

query: fixed race condition

parent 5f313283
......@@ -52,6 +52,12 @@ type queryFunc func(context.Context, peer.ID) (*dhtQueryResult, error)
// Run runs the query at hand. pass in a list of peers to use first.
func (q *dhtQuery) Run(ctx context.Context, peers []peer.ID) (*dhtQueryResult, error) {
select {
case <-ctx.Done():
return nil, ctx.Err()
default:
}
ctx, cancel := context.WithCancel(ctx)
defer cancel()
......@@ -104,6 +110,15 @@ func (r *dhtQueryRunner) Run(peers []peer.ID) (*dhtQueryResult, error) {
r.addPeerToQuery(r.cg.Context(), p)
}
// may be closed already. this caused an odd race (where we attempt to
// add a child to an already closed ctxgroup). this is a temp workaround
// as we'll switch to using a proc here soon.
select {
case <-r.cg.Closed():
return nil, r.cg.Context().Err()
default:
}
// go do this thing.
// do it as a child func to make sure Run exits
// ONLY AFTER spawn workers has exited.
......
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