From e6a4d6a3dd25986e59f44e11e8250d59986c942f Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 27 Feb 2020 17:47:15 -0800 Subject: [PATCH] fix(query): cancel the context when the query finishes --- query.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/query.go b/query.go index c0211a56e..325101145 100644 --- a/query.go +++ b/query.go @@ -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