Repository navigation
Conversation
A direct-mode job was stopped by a signal to its shell only. Processes that the job started could survive a cancel, a timeout, an OOM kill or Ctrl-C, and SIGINT or SIGHUP killed the runner and left its jobs running. - Start each job in a session of its own, with stdin from /dev/null. The job's process group is signaled as a whole. A job that uses the terminal can no longer be stopped by the kernel. - A stop signals the process group first, then lists the processes of the host once per pass and signals the descendants outside the group. The delay until the signal is the same as before. - A job is complete when its shell is reaped, its group is empty and the recorded descendants are gone. Processes left after the shell exits get sigterm_lead_seconds, then the termination signal, then SIGKILL. - SIGINT and SIGHUP stop the jobs like SIGTERM. After cleanup the runner dies by the same signal, so a calling script stops. An ignored SIGINT stays ignored. - When the server is unreachable during a stop, the runner stops its jobs with the usual grace and exits instead of retrying. - A stopped job goes through output-file validation. - torc -s run starts the standalone server in a process group of its own, so Ctrl-C does not kill it before results are recorded. Slurm mode and Windows are unchanged. Windows stops only the job's own process.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is the first of four stacked PRs that make direct mode usable as a local execution backend for
an external engine that submits, polls and cancels jobs one at a time. This PR changes the runner
only: no API, database or Slurm change. The later PRs are listed at the end.
Before this PR, a direct-mode job was stopped by a signal to its shell only:
a timeout, an OOM kill or a runner shutdown.
runningon the server.sigterm_lead_secondseven when alljobs had already exited, and retried forever when the server was unreachable.
What changes
Each job runs in a session of its own. The job is started with
setsidand stdin from/dev/null. Its process group ID and session ID equal the job's PID, so the runner can signal thegroup as a whole. The job has no controlling terminal, so a job that reads the terminal gets an
error instead of being stopped by the kernel.
A stop reaches the whole tree.
AsyncCliCommand::request_stop(reason, signal, grace)sends thesignal to the process group, waits for the grace period, then sends SIGKILL. All stop paths use it:
cancel, runtime limit, end of the allocation, OOM (SIGKILL at once) and runner shutdown.
Descendants outside the group. A launcher can put its children into groups of their own. After
the group is signaled, the runner lists the processes of the host once per pass (one listing for all
jobs), records every descendant outside the group with its start time, and sends it the same signal.
A descendant is a member of the job's session or a process reached from the job's shell by parent
PID.
A job is complete only when its tree is gone. That means: the shell is reaped, the group is
empty (or holds only zombies) and the recorded descendants are gone. Processes that are left after
the shell exits get
sigterm_lead_seconds, then the termination signal, then SIGKILL. So a job thatends with
nohup worker &no longer leavesworkerbehind.Signals to the runner.
signal, so a script
torc run ...; next_stepstops on Ctrl-C. SIGTERM still exits 0.nohup torc run) stays ignored.exits. In Slurm mode the retry loop is unchanged.
running.Standalone mode.
torc -s runstarts its server in a process group of its own. Before, Ctrl-Cin the terminal killed the server before the runner could record the results.
Behavior changes to review
torc runrunningterminated, runner dies by the signaltorc run, jobs exit fastsigterm_lead_secondscompletedfailed(goes through output-file validation)/dev/ttyor runsbash -iMeasurements (Linux x86_64, 8 cores, debug build)
main: 20s, the full
sigterm_lead_seconds).s, last 0.13 s.
main: first 0.00 s, median 0.05 to 0.08 s, last 0.11 to 0.12 s.setsidneedspre_exec, so the standard library uses fork instead ofposix_spawn.That costs about 1 ms per job start (1000 short jobs: 4.4 s,
main: 3.3 s).Limits
setsid) is found only if its parent is stillrunning right after the signal, as a launcher that shuts its children down is. A daemon whose
parent exited is not found and keeps running. Listing the processes before the signal would find
more of these, but it delays the signal to every job by the time of the listing (about 0.2 s with
200 jobs).
Tests
tests/test_async_cli_command.rs: stop of a tree with children, grace then SIGKILL, a child in aprocess group of its own, a child in a session of its own, leftovers after the shell exits, a
shared process table, session and stdin of the job.
tests/test_direct_mode_e2e.rs: SIGINT, SIGHUP and SIGTERM to the runner (exit status and jobstatus), unreachable server, ignored SIGINT, a stopped job without its output file, a job that
uses the terminal.
tests/test_standalone.rs: Ctrl-C ontorc -s runrecords the jobs.cargo fmt -- --check,cargo clippy --all --all-targets --all-features -- -D warningsanddprint checkpass.cargo nextest run --all-features --no-fail-faston the branch merged withmain(7811e80b):2020 of 2021 passed. The one failure,
test_get_active_task_returns_running_taskintests/test_tasks.rs, also fails now and then onmain: it races an asyncinitialize_jobstaskagainst a second request.
Not verified
#[cfg(unix)]and has non-Unixfallbacks, but only CI will show whether Windows builds. There is no macOS CI job.
test_request_stop_terminates_mpi_ranksis ignored by default and needsmpirun. Runit with
cargo nextest run --all-features --run-ignored only -E 'test(test_request_stop_terminates_mpi_ranks)'.Docs
docs/src/core/concepts/execution-modes.md,job-runners.md,job-states.mdanddocs/src/core/how-to/cancel-workflow.mddescribe the new behavior and the limits.docs/src/specialized/design/process-tree-termination.md.Follow-up PRs
This PR is draft until the design is agreed. Three more PRs finish the work, each based on the one
before:
is_workflow_completepoll, stops the job through the stop path of this PR and reportscanceled.external_id(arepeated submit returns the same job) and a
working_dir.runner (
torc run --exclusive), atermination_reasonon results and an opt-in per-job runtimelimit.