Repository navigation
Fix interrupt pass reporting a group gone before its leader is reaped (#2088) - #2218
Conversation
Refs #2088. Assisted-by: Claude Code:claude-fable-5-2
A pass of the interrupt handler over a build's process group says the group is gone when the group probe finds no member, whether or not the build's own child has been reaped. The new test puts a pass in that state with a child that leads no group, and fails. Refs #2088. Assisted-by: Claude Code:claude-fable-5-2
An interrupt pass called a build's process group gone as soon as the group probe found no member. macOS stops counting an exiting process in its group before its parent can wait for it, so a pass could say so with the group's leader not yet waitable, and leave the leader unreaped. The nightly macOS run failed on that in an_interrupt_pass_ends_the_whole_build_group. A pass now calls the group gone only once a wait for the leader has answered: reaped by this pass, or already reaped by an earlier pass or by the build's own thread. Fixes #2088. Assisted-by: Claude Code:claude-fable-5-2
|
bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview Adds Reviewed by Cursor Bugbot for commit f764d43. Configure here. |
Wenxin Jiang (Wenxin-Jiang)
left a comment
There was a problem hiding this comment.
[agent] Reviewed the interrupt loop and the regression where the group probe cannot see a live child. The pass now requires both conditions, with the existing bounded retry loop.
LLM Description written by Claude Code:claude-fable-5-2
Fixes #2088
Summary
The nightly macOS run fails now and then on
utils::process::tests::an_interrupt_pass_ends_the_whole_build_group("the pass reaped the build's child itself"). The test is right and the code
under it has a race: a pass of the interrupt handler can report a build's
process group gone while the group's leader has not been reaped. This PR
makes a pass wait for the leader, and adds a test that shows the race on
every Unix, not only on macOS.
One file changes:
crates/socket-patch-core/src/utils/process.rs(8 linesof code in
end_build_group, one new test, one clearer assert message).Root cause
end_build_groupsends SIGKILL to the group, callswaitpid(WNOHANG)onthe leader, probes the group with
kill(-pgid, 0), and returned whateverthe probe said. It never looked at what
waitpidanswered. macOS stopscounting an exiting process as a member of its group before its parent can
wait for it. In that window the probe finds nobody, both waits answer 0
("not exited yet"), and the pass says "gone" with the leader unreaped. The
test then finds the child still waitable.
That reading of macOS comes from the failure itself (the assertion can only
fail if a pass returned true without a successful wait); I could not run
macOS here.
Fix
A pass now reports the group gone only when the probe finds nobody and a
wait for the leader has answered something other than 0: reaped by this
pass, or already reaped (
ECHILD) by an earlier pass or by the build's ownthread. The leader is this process's own child, so the wait is the one
certain sign that it is dead.
kill_builds_on_interruptstill gives upafter its 400 passes (about 2 s), so the handler cannot hang.
Behavior for users: on an interrupt, the apply lock is released slightly
later on macOS in the rare window above (a few milliseconds), never earlier
than before.
Evidence
an_interrupt_pass_waits_for_the_leader_the_group_probe_missed(covers Flake: an_interrupt_pass_ends_the_whole_build_group fails on macOS ("the pass reaped the build's child itself") #2088). It puts a pass in the same state on Linux with a child
that leads no group: the probe finds nobody and the child is not waitable.
the pass called a group gone over its live leader.cargo test -p socket-patch-core --lib an_interrupt_passrepeated 30times: 30 passes.
cargo test -p socket-patch-core: all pass (8357 in the lib).cargo clippy --locked -p socket-patch-core -p socket-patch-cli --all-features -- -D warnings(CI's form): clean.
an_interrupt_pass_ends_the_whole_build_grouponly flakes on macOS, sothe macOS
testjob on this PR and the next nightly runs are the realconfirmation there.
Review notes (
/code-review high)No finding against this change. It reported three things that were already
true before it, which I left alone to keep this PR to one cause:
kill(-pgid, 0)failure as "nobody left",EPERMincluded (a member running as another user).after the leader was reaped, so in theory the pid could be recycled.
and uncounted when the pass reports the group gone. It has been sent
SIGKILL by then.
And one nit, not taken:
waitpidreturning -1 is read as "reaped" withoutchecking that
errnoisECHILD. WithWNOHANGno other error isreachable for a pid this process spawned.
https://claude.ai/code/session_011f9aeRgAtMGHGSBTPPnhKe
Generated by Claude Code