Skip to content

Commit

Permalink
jobs: avoid a dangling goroutine
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
knz committed Mar 13, 2023
1 parent e0cfcc1 commit cd7b335
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/jobs/adopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down

0 comments on commit cd7b335

Please sign in to comment.