Skip to content

Commit

Permalink
Merge pull request #467 from libp2p/fix/cleanup-goroutines
Browse files Browse the repository at this point in the history
fix(query): cancel the context when the query finishes
  • Loading branch information
Stebalien authored Feb 28, 2020
2 parents 30ba05e + e6a4d6a commit 4838fd5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ func newQueryRunner(q *dhtQuery) *dhtQueryRunner {
}

func (r *dhtQueryRunner) Run(ctx context.Context, peers []peer.ID) (*dhtQueryResult, error) {
// Make sure to clean everything up when we return from this function.
ctx, cancel := context.WithCancel(ctx)
defer cancel()

r.log = logger
r.runCtx = ctx

Expand Down

0 comments on commit 4838fd5

Please sign in to comment.