diff --git a/query.go b/query.go index c0211a5..3251011 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