perf: process kill wait loop and PID polling jitter#627
Merged
Conversation
- Add process.wait() after kill() to verify termination and prevent zombie processes - Add +/-20% random jitter to PID file polling interval to prevent thundering herd when multiple kild create commands run simultaneously - Switch daemon from multi-threaded tokio runtime to current_thread since it's I/O-bound with low concurrency (PTY reads + IPC) Closes #478
- Replace process.wait() with bounded 500ms poll loop to avoid blocking indefinitely on uninterruptible sleep - Use PID-based jitter instead of SystemTime nanos which are correlated across simultaneous launches - Revert current_thread runtime: daemon multiplexes PTYs + IPC across multiple sessions, single-threaded would stall all sessions on any slow operation
Owner
Author
PR Review SummaryCritical Issues (1 found)
Fix: Remove the third summary bullet ("Switch daemon from multi-threaded tokio runtime…") and retitle to e.g. Important Issues (2 found)
Suggested fix for both (combined): // Reuse the already-populated `system` to poll for termination
let mut process_exited = false;
let deadline = std::time::Instant::now() + std::time::Duration::from_millis(500);
while std::time::Instant::now() < deadline {
system.refresh_processes(ProcessesToUpdate::Some(&[pid_obj]), true);
match system.process(pid_obj) {
None => { process_exited = true; break; }
Some(_) => {}
}
std::thread::sleep(std::time::Duration::from_millis(10));
}
if !process_exited {
debug!(
event = "core.process.kill_wait_timeout",
pid = pid,
message = "process did not exit within 500ms after SIGKILL"
);
}This (a) avoids up to 50 redundant Suggestions (2 found)
Strengths
Verdict: NEEDS FIXES
|
- Reuse existing `system` in kill wait loop instead of allocating a new System::new() on each of up to 50 poll iterations - Add debug log when kill wait times out (process didn't exit within 500ms after SIGKILL) - Hoist constant jitter calculation above the polling loop - Align docstring to use "decorrelate" instead of "thundering herd"
- Replace exited flag with early return on process exit - Use elapsed() pattern consistent with read_pid_file_with_retry - Remove unnecessary signed-integer casts in jitter computation — stays in u64 since BASE_INTERVAL_MS (100) > JITTER_RANGE_MS (20)
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
kill()— polls for up to 500ms to verify process termination, logs timeout if process survives SIGKILLkild createlaunchesItems 1 (Cow newtypes), 2 (git caching — each call opens a different worktree path), 3 (current_thread runtime — reverted, daemon runs fine on multi-threaded), and 6 (HashMap keys are tiny pane IDs) from #478 were evaluated and skipped as YAGNI for this codebase.
Closes #478
Test plan
cargo fmt --checkpassescargo clippy --all -- -D warningspassescargo test --allpasses (2 pre-existing failures inresolve_self_branchunrelated to this PR)kild create+kild stopto verify process cleanupkild createcommands to verify jitter prevents lock contention