diff --git a/.changelog/11741.txt b/.changelog/11741.txt new file mode 100644 index 000000000000..1302fc2e3e39 --- /dev/null +++ b/.changelog/11741.txt @@ -0,0 +1,3 @@ +```release-note:bug +client: Fixed a memory and goroutine leak for batch tasks and any task that exits without being shut down from the server +``` diff --git a/client/allocrunner/taskrunner/task_runner_hooks.go b/client/allocrunner/taskrunner/task_runner_hooks.go index c9ff34441ed5..72a509e056c7 100644 --- a/client/allocrunner/taskrunner/task_runner_hooks.go +++ b/client/allocrunner/taskrunner/task_runner_hooks.go @@ -237,7 +237,9 @@ func (tr *TaskRunner) prestart() error { // Run the prestart hook // use a joint context to allow any blocking pre-start hooks // to be canceled by either killCtx or shutdownCtx - joinedCtx, _ := joincontext.Join(tr.killCtx, tr.shutdownCtx) + joinedCtx, joinedCancel := joincontext.Join(tr.killCtx, tr.shutdownCtx) + defer joinedCancel() + var resp interfaces.TaskPrestartResponse if err := pre.Prestart(joinedCtx, &req, &resp); err != nil { tr.emitHookError(err, name)