Repository navigation
fix: align utilityProcess kill() with child_process.kill() - #53992
Conversation
UtilityProcessWrapper::Kill() opened a second base::Process for the child, sent SIGTERM and then handed it to base::EnsureProcessTerminated, which on POSIX reaps the child itself (immediately via kqueue on macOS, after a 2s delay on Linux). content's BrowserChildProcessHostImpl reaps the same child once its mojo pipe drops, via base::GetKnownDeadTerminationStatus. Whichever side lost that race failed: content's kill(SIGKILL) hit ESRCH and its waitpid() hit ECHILD, logging "ERROR:base/process/kill_posix.cc:87 Unable to terminate process" and "kill_posix.cc:33 waitpid(): No child processes" (about 1,200 lines per main CI run), and the exit code content reported was derived from a status that was already gone. content reaps reliably on its own, so only keep base's helper on Windows. On POSIX send SIGTERM and post a delayed SIGKILL that fires only if the wrapper has not yet seen the child terminate, matching the 2s grace period base::EnsureProcessTerminated used. waitpid now reports the signal, which HandleTermination already maps to exit code 0. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01AFucMLGyVVqSUAKXrqbaUT
ca60bc1 to
5507bf0
Compare
Review feedback on the previous commit: the delayed SIGKILL was posted to the UI thread, so it could not run while main-process JavaScript kept that sequence busy, and a child that ignores SIGTERM could outlive kill() indefinitely. The base::EnsureProcessTerminated call it replaced enforced its two-second deadline on a background thread. Post the fallback to a ThreadPool sequence (MayBlock, BEST_EFFORT) instead. The task takes only the pid and the child's base::Process::CreationTime(), read before SIGTERM while the child is certainly alive, and re-reads the creation time when it fires: once content has reaped the child the pid yields a null time, and a reused pid yields a different one, so neither is signalled. A not-yet-reaped zombie matches and accepts SIGKILL harmlessly. No wrapper state is touched off the UI thread, so nothing has to be marshalled back, and the ForceKill member goes away. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01AFucMLGyVVqSUAKXrqbaUT
deepak1556
left a comment
There was a problem hiding this comment.
Didn't realize this race when implementing the original kill api , good find!
However, should we take this opportunity to avoid the delayed kill that was accidentally introduced in 489d3ac . The process kill api contract was to align with Node.js child_process.kill whose contract is also delivering the signals to the process not ensuring they terminate. We now have chromium handling the reap on pipe disconnection when the process terminates (this was not known at the time of implementation so I had introduced eager base::EnsureProcessTerminated), for cases where a utility process installs SIGTERM handler so far we have been force killing it unintentionally. Should we preserve that or not ?
process.on('SIGTERM', async () => {
await flushState();
// The process decides when—or whether—to exit.
});
|
Agreed this is the moment to decide the escalation rather than just move it between threads. What the tree promises today: My recommendation: drop it and match If you'd rather preserve the escalation, the current head (c6f905e) does that off the UI thread per @ckerr. Say which and I'll push it. Generated by Claude Code |
|
Make the recommended change that aligns with |
Kill() now only delivers the signal: base::Process::Terminate() sends SIGTERM on POSIX and calls TerminateProcess on Windows, and nothing else happens. The base::EnsureProcessTerminated call introduced in 489d3ac (#34980) is gone on every platform, and with it the ThreadPool SIGKILL fallback from the previous commit. EnsureProcessTerminated reaped the child itself and SIGKILLed it after 2s, which raced content's BrowserChildProcessHost reap (its kill()/waitpid() then failed with ESRCH/ECHILD and logged two ERROR lines per kill) and force-killed a child that handles SIGTERM. Like Node's child_process.kill(), delivery is now all kill() guarantees; content reaps the child once its mojo pipe drops. The docs for child.kill() describe the new contract, with an API history entry, and a POSIX spec forks a child whose SIGTERM handler exits with 42 after 2.5s and asserts that kill() lets it. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01AFucMLGyVVqSUAKXrqbaUT
|
@deepak1556 Done in 76b02e0: Generated by Claude Code |
|
Release note looks good now. |
Apply review nits: drop the API-history block under `child.kill()`, note the behavior change under Breaking API Changes (46.0) in docs/breaking-changes.md instead, and say that the child is reaped by Electron on POSIX. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01AFucMLGyVVqSUAKXrqbaUT
|
API LGTM |
|
Release Notes Persisted
|
Requested by John Kleinschmidt · Slack thread
Description of Change
Before: every
utilityProcess.kill()on macOS and Linux made the browser process reap the child itself.UtilityProcessWrapper::Kill()sent SIGTERM and handed the process tobase::EnsureProcessTerminated, which reaps the child (immediately via kqueue on macOS, after ~2s on Linux) and SIGKILLs it after 2 seconds. content'sBrowserChildProcessHostImplreaps the same child once its mojo pipe drops, so content's ownkill(SIGKILL)failed with ESRCH and itswaitpid()failed with ECHILD, loggingERROR:base/process/kill_posix.cc:87 Unable to terminate processandkill_posix.cc:33 waitpid(): No child processesfor each kill (about 1,200 lines per main CI run, e.g. https://github.com/electron/electron/actions/runs/35042445438). A child that handled SIGTERM to finish its work was force-killed 2 seconds later regardless.After:
kill()only delivers the signal: SIGTERM on POSIX,TerminateProcesson Windows. content reaps the child exactly once, so the ERROR lines are gone and the exit code comes from the realwaitpidstatus (the SIGTERM signal, whichHandleTerminationalready maps to0). A child that handles SIGTERM exits on its own terms, matching Node'schild_process.kill(), which delivers the signal and guarantees nothing more. This is the change @deepak1556 asked for in #53992 (comment).How:
Kill()isbase::Process::Open(pid_).Terminate(RESULT_CODE_NORMAL_EXIT, false)and nothing else, on every platform.base::EnsureProcessTerminated(introduced in 489d3ac / #34980) is removed along with the ThreadPool SIGKILL fallback from an earlier revision of this PR, the now-unused includes, and the stale crbug 818244 / zygote comment. Thechild.kill()docs describe the new contract, the change is recorded with a Behavior Changed entry in docs/breaking-changes.md, and a POSIX spec forks a child whose SIGTERM handler exits with 42 after 2.5 seconds and asserts thatkill()returnstrueand the child exits with 42.Validation: no Electron build is available in this environment, so the C++ compiles for the first time in CI;
clang-format --dry-run -Werrorwith the repo.clang-formatis clean. Lints run locally and passing:lint:js,oxfmt --checkon the spec and fixture,markdownlint-cli2,lint:js-in-markdown,lint:docs-relative-links. The new spec was run against the prebuilt46.0.0-nightly.20260915(which still has the 2s force-kill) withscript/spec-runner.js --electronVersion=... -g kill: the existingkill()test passes and the new test fails there withexpected +0 to equal 42, which is the behaviour this PR removes and shows the test discriminates. It cannot pass until CI builds this branch.Checklist
npm testpasses🤖 Generated with Claude Code
https://claude.ai/code/session_01AFucMLGyVVqSUAKXrqbaUT
Release Notes
Notes:
child.kill()onutilityProcessnow sendsSIGTERMon POSIX likechild_process.kill()and no longer force-kills a child that handles the signal.