Skip to content

fix(proc): a kill before the child's setsid reaches the child - #18

Merged
HaoZeke merged 2 commits into
mainfrom
fix/cancel-before-setsid
Nov 16, 2026
Merged

HaoZeke merged 2 commits into
mainfrom
fix/cancel-before-setsid

Conversation

@HaoZeke

@HaoZeke HaoZeke commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

proc.run could miss a child that had not yet called setsid. The child makes its process group with setsid after the fork, but run publishes the pgid and can signal the group at once. A cancel flag that was already set, a timeout with no grace, or a stopGroup on a just-published pgid therefore sent SIGKILL to a group that did not exist yet, so the child ran to the end and what it started outlived the call.

A group signal that finds no group now goes to the child itself, which has started nothing before it execs, and then to the group again in case the child made it in between. The change is in the one private helper that cancel, timeout and stopGroup share, and it still uses only system calls, so stopGroup stays safe inside a signal handler.

Two new tests cancel, or call stopGroup, as soon as the child is forked, a hundred times each. Both fail on main natively and under QEMU and pass with the fix. "a set cancel flag kills the child" now takes milliseconds instead of 30 s.

The tools matrix (eb-keep-logs, eb-local, eb-staged-rebuild, eessi-arch-guard) gives the same results as on main.

The child makes its process group with setsid after the fork, while run
publishes the pgid and can kill the group at once. A cancel flag set
before the call sends that kill before the child has run, the kill finds
no group, and the child runs its script: the call waits until it exits,
and what it started outlives the call. A stopGroup on the pgid as soon
as it is published misses the same way. Each test makes a hundred calls
to a script that starts a background sleep and sleeps two seconds, and
checks that each returns within a second and leaves nothing alive; the
stopGroup one runs on one CPU, where the stop comes first nearly every
time. Both fail until a group kill reaches a child that has not made its
group.
The child makes its process group with setsid once it runs, but run
publishes the pgid and can signal the group straight after the fork. A
cancel or a timeout that came first, or a stopGroup on the pgid just
published, found no group and missed: "a set cancel flag kills the
child" waited out its sleep 30, and a handler that stops the group and
exits left the child running. A group signal that finds no group now
goes to the child itself, which starts nothing before it execs, and then
to the group again in case the child made it in between. Once the group
exists nothing changes, and stopGroup stays safe in a signal handler.
Waiting for the child to make its group or to exec would hold run before
it can honor a cancel or a deadline, and a setpgid in the parent as well
would make the child's setsid fail.
@HaoZeke
HaoZeke merged commit 036d5e4 into main Nov 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant