Repository navigation
Conversation
process_spawner_init() forks a spawner and calls setpgid() from both the parent and the child, so that either order leaves the spawner in its own process group. Any failure other than EACCES in the parent was fatal. On macOS, setpgid() returns EPERM when the other side has already moved the process, and occasionally under load when many processes start at once. btllib then exits with "setpgid failed in ... process". In GoldPolish this killed polishing in 2 of 9 runs on an Apple Silicon Mac and left one run hung, waiting on a helper that had exited. - Treat setpgid() as successful when the process already leads its own group (getpgrp()/getpgid() == pid), from either side. - Retry EPERM briefly (up to 200 attempts, 0.5 ms apart). - Check the return value of fork(). A failed fork (e.g. at the per-user process limit) went on to call setpgid(-1, -1) and was reported as "setpgid failed in parent process". This is the likely cause of that message in BirolLab/goldpolish#11, which raising ulimit -u resolved. It now reports "fork failed" and the reason. - Include strerror() in the setpgid error messages. Tested on macOS (Apple Silicon, arm64): GoldPolish ran 20 of 20 times without failures or hangs, and the GoldRush demo passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lcoombe
approved these changes
Oct 27, 2026
Contributor
There was a problem hiding this comment.
Looks fine to me!
Note that we haven't seen the error on macOS CI here or in the goldpolish repo, so this may be an issue limited to apple silicon - there are unfortunately not any free macOS ARM64 images currently available in azure devops, so we can't add that to CI.
It would be good to get a review from @jwong-1 and/or @parham-k as well before we merge.
This branch has not been deployed
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.
On macOS, btllib's process spawner exits with
setpgid failed in ... processunder ordinary load. This PR makessetpgid()failures fatal only when the spawner really did not end up in its own process group, and checksfork().Problem
process_spawner_init()forks the spawner and callssetpgid()from both the parent and the child, so the spawner is in its own group whichever runs first. Any failure other thanEACCESin the parent, and any failure in the child, exits the program.On macOS,
setpgid()returnsEPERMin two cases where nothing is wrong:Every program linked to btllib runs this at startup, and GoldPolish starts many of them in parallel. On an Apple Silicon Mac, polishing the GoldRush demo data failed in 2 of 9 runs. A third run hung, waiting on a helper that had exited.
Separately, the return value of
fork()is never checked. Whenfork()fails, for example at the per-user process limit, the parent callssetpgid(-1, -1)and reportssetpgid failed in parent process. This is the likely cause of that message in BirolLab/goldpolish#11, which raisingulimit -uresolved.Change
In
src/btllib/process_pipeline.cpp,process_spawner_init():setpgid()as successful when the process already leads its own group (getpgrp() == getpid()in the child,getpgid(pid) == pidin the parent).EPERMup to 200 times, 0.5 ms apart. Other errors fail immediately, as before. The retry is needed: with only the group-leader check, 1 of 10 GoldPolish runs still hung.fork()and reportfork failed: <reason>.strerror()in thesetpgiderror messages.On Linux, behaviour is unchanged unless
setpgid()fails, which the existing code already treated as fatal.Testing
All on macOS with Apple Silicon (arm64); not run on Linux.
goldrush-ulimittests/goldrush_test_demo.sh)setpgid(0, 0)returnedEPERMwhile not yet a group leader 5 times in 57,600 forks, over six runs. It is rare, so run the program a few times. In the three runs that also retried, all 4 such failures succeeded on the second attempt. The code is below.meson test --repeat=5on adebugoptimizedbuild: 100 of 100 passed (20 tests, 5 times each).Reproducer (C)
🤖 Generated with Claude Code