Repository navigation
Keep killing an exec step's group until it is empty when mav dies - #177
Merged
Merged
Conversation
A signal sent to a whole process group can skip a member that is in the middle of fork(). The exec-step watchdog sent one SIGKILL to the group from inside it, so a shell polling with sleep, or a make starting compilers, could outlive a SIGKILLed mav with nothing left to stop it. The watchdog now starts in a group of its own (set -m, then set +m before the step's command) and repeats the SIGKILL until kill fails, which only happens once the group is empty. The background helper watchdog repeats its final SIGKILL the same way.
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.
TestExecStepShellDoesNotSurviveMavfailed now and then when severalmake checkruns shared the machine. The test was right. The exec-step watchdog from #121 can really leave the step's shell running under launchd aftermav runis SIGKILLed.Cause
The watchdog read EOF on the death pipe and sent one
kill -KILL -$$to the step's process group, from inside that group. On macOS a signal sent to a whole process group can skip a member that is in the middle offork(). A shell pollinguntil [ -f … ]; do sleep 0.05; doneforks twenty times a second, and so does amakestarting compilers. When the skip hit, the watchdog's kill ended the watchdog itself, and nothing was left to send a second one.Evidence, from instrumented runs of the test (a trace line from the watchdog plus
ps/lsofof the group on failure):In every failure the watchdog logged that it read EOF, sent the group SIGKILL and died from it. The shell was still alive with
ppid 1, still forkingsleep, and no other process held the pipe.Same binary and the same load, run at the same time, 150 iterations each:
sleep 1000, which never forks: 0 survived.So the group signal skips a process that is forking, and that isn't specific to the leader.
Fix
watchParentShell): the watchdog starts underset -m, so it gets a process group of its own.set +mswitches job control off again before the step's command runs, so anything the command starts stays in the step's group as before. After EOF the watchdog repeatskill -KILL -$$untilkillfails, which only happens once the group is empty. The pgid can't be reused while a member still holds it, so the loop never signals a stranger.reapProcessGroup. The watchdog then backs up that single reap: on an empty group its first kill fails and it exits.TestExecStepShellDoesNotSurviveMavfails, its message now lists the group (ps), so the next failure shows who is still there.TestExecStepWatchdogLivesOutsideTheStepsGroupchecks that the watchdog sits outside the step's group, which is what lets it retry, and that it is gone once a normal step ends, so the new design doesn't leak a process per step.Validation
GOFLAGS=-count=1 make check, run at the same time in this checkout and in agit archive HEADextract, 4 rounds each: 8 of 8 passed.TestExecStepShellDoesNotSurviveMavlooped with the same load on both sides, old binary vs. this branch, run at the same time:Ablation: with the old one-shot, in-group watchdog put back,
TestExecStepWatchdogLivesOutsideTheStepsGroupfails withwatchdog N is in the step's process group M; its first kill would end it before it could retry. With the fix it passes.set -m/set +mchecked with/bin/bash3.2 both without a terminal and inside a pty, with the shell in a group of its own asSetpgidputs it. The watchdog gets its own pgid, the command's later background jobs stay in the shell's group, and nothing is printed or stopped.