Sign in or sign up before continuing. Don't have an account yet? Register now to get started.
Graceful Job Termination
When execution of a job times out or is cancelled, we should let the corresponding processes exit gracefully.
[Relevant conversation](https://gitlab.com/gitlab-org/step-runner/-/merge_requests/302#note_2847110893).
Sub-process termination in `step-runner` is ultimately handled [here](https://gitlab.com/gitlab-org/step-runner/-/blob/main/pkg/runner/executable_step.go?ref_type=heads#L80) in the executable step. Canceling the context used in `exec.CommandContext` will terminate subprocess, but not necessarily gracefully. From the [relevant Go docs](https://pkg.go.dev/os/exec#CommandContext):
> CommandContext sets the command's Cancel function to invoke the Kill method on its Process, and leaves its WaitDelay unset. The caller may change the cancellation behavior by modifying those fields before starting the command.
So to enable graceful termination we have to both set `Cmd.WaitDelay` and set a custom `Cancel` method that does not immediately `Kill` the subprocess.
In addition, we'll want to expose a graceful-exit-delay value in the RunRequest, and then connect that to the `Cmd.WaitDelay` above.
issue