Repository navigation
fix(dvm): keep a worker killable after it closes stdout - #1258
Conversation
drive_worker polled the kill request only inside the stdout-reading loop. Once stdout closed, it blocked in process.wait() with nothing polling the receiver, so a later kill (a job timeout, a stalled stdin write, shutdown) never reached a child that finished its output and hung. The wait now runs in a select! with the kill request; a receiver that already fired is not polled again. Closes #1102 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 53d92d0)
🦋 Changeset detectedLatest commit: f201324 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
[Medium impact] The PR appears safe to merge; the remaining test timing race is non-blocking. Findings
|
| let fixture = build(worker(vec!["-c", &script], 500), true); | ||
| let shutdown = ShutdownState::new(); | ||
| let running = tokio::spawn(Arc::clone(&fixture.orchestrator).run(shutdown.clone())); | ||
|
|
||
| // Written by rename, so it is never read half-written; awaited before the 500 ms timeout. | ||
| let pid = tokio::time::timeout(Duration::from_secs(5), async { | ||
| loop { | ||
| if let Ok(pid) = std::fs::read_to_string(&pid_file) { | ||
| return pid.trim().to_owned(); | ||
| } | ||
| tokio::time::sleep(Duration::from_millis(10)).await; | ||
| } | ||
| }) | ||
| .await | ||
| .expect("the child closed stdout and wrote its pid"); | ||
| assert!(alive(&pid), "the child is running before its timeout"); |
There was a problem hiding this comment.
The test starts the 500 ms job timeout without waiting for the child to write its PID. On a busy runner, the timeout can kill the child before the file appears or before alive(&pid) runs. The test then fails even when the fix works. Gate job dispatch on the child's readiness, then check that the timeout kills it.
…eout The 500 ms job timeout was also the window in which the child had to spawn, close stdout and write its pid. A child delayed 600 ms failed the test with the fix in place (measured), so a loaded runner could flake it. At 3 s the observation window is the spawn latency's; the assertion that matters still runs, and with the fix reverted the test fails where it should - the child still alive after its kill request.
|
Confirmed, and fixed in The fix is the one you describe, done on the timeout rather than on extra synchronisation: the job timeout is now 3 s, so the observation window is the spawn latency's rather than the kill's, and Re-verified with the widened window:
|
Description
drive_workerincrates/nostream-services/src/workers/dvm_orchestrator.rspolled the kill request only while it was reading the child's stdout. Once that stream ended — a worker that finished its output and hung, or one whose output went elsewhere — it blocked inprocess.wait()with nothing polling the receiver, so any kill raised afterwards (job timeout, stalled stdin write, shutdown) reached no one. The child lived until it exited on its own or the orchestrator itself was dropped.The wait now runs in a
select!alongside the kill request. A receiver that already fired is not polled again, so the already-killed path keeps its plain wait.Opened on @AgrimTawani's behalf from their fork commit
53d92d07(branchfix/1102-kill-after-stdout-closes), cherry-picked with-xso authorship and origin are preserved. They reported they cannot open the PR themselves.Related Issue
Closes #1102
Motivation and Context
The issue's reproduction — a DVM worker that finishes its output and then hangs — stayed alive through its job timeout: the kill reached nothing, so the slot was never reclaimed and the hung child outlived the job that owned it.
How Has This Been Tested?
New test
a_worker_that_closed_stdout_is_still_killed_on_timeoutincrates/nostream-services/tests/dvm_worker.rs. The child closes stdout, writes its pid by rename (so the file is never read half-written), thenexecssleep 60; the test asserts the pid is alive before the 500 ms timeout and gone within 5 s of the kill.cargo fmt --all --check— cleancargo clippy --workspace --all-targets --all-features -- -D warnings— cleancargo test -p nostream-services --test dvm_worker— 12 passed, 0 faileddvm_orchestrator.rshunk reverted and the test kept, the new test fails (0 passed, 1 failed: the child is still alive 5 s after its kill request); restoring the hunk makes it pass. The test therefore detects the defect it names rather than passing either way.cargo test --workspace --all-features— exit 0; every test binary reportsok, no failuresNo hidden Unicode in the three changed files; the changeset is Rust-only.
Types of changes
Checklist