From cd7b335588256b7cfbae3485a28a9654c59a1104 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Mon, 13 Mar 2023 22:20:26 +0100 Subject: [PATCH] jobs: avoid a dangling goroutine Release note: None --- pkg/jobs/adopt.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/jobs/adopt.go b/pkg/jobs/adopt.go index 90a36af323e5..51fa93c61b67 100644 --- a/pkg/jobs/adopt.go +++ b/pkg/jobs/adopt.go @@ -323,6 +323,8 @@ func (r *Registry) resumeJob( resumeCtx = multitenant.WithTenantCostControlExemption(resumeCtx) } if alreadyAdopted := r.addAdoptedJob(jobID, s, cancel); alreadyAdopted { + // Not needing the context after all. Avoid leaking resources. + cancel() return nil } @@ -333,6 +335,8 @@ func (r *Registry) resumeJob( _ = r.runJob(resumeCtx, resumer, job, status, job.taskName()) }); err != nil { r.unregister(jobID) + // Also avoid leaking a goroutine in this case. + cancel() return err } return nil