Repository navigation
fix(terminal): preserve signal masks across concurrent worker spawns - #20
Merged
Merged
Conversation
Use pthread_sigmask around POSIX spawning. On Darwin, overlapping sigprocmask calls save and restore another worker’s temporary process-wide blocked mask, leaving child SIGINT blocked even though terminal writes succeed. Add synchronized Worker terminal SIGINT coverage. The regression times out on the unfixed release and passes with this change; the original two-worker repro passes 56 iterations per worker. Release terminal/spawn suites retain only the two baseline internal-for-testing import errors. Windows x64/arm64 Rust type checks pass; runtime validation was macOS arm64.
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.
What does this PR do?
Fixes lost Ctrl-C in
Bun.Terminalchildren on macOS when two threads spawn processes at the same time.posix_spawn_buninsrc/jsc/bindings/bun-spawn.cppblocks all signals around the spawn and then restores the previous mask. It usedsigprocmask, which changes the whole process's mask on Darwin, not just the calling thread's. When two threads (for example twoWorkers) spawn at the same time, the second saves the first one's temporary all-blocked mask as its "old" mask and later restores it. The process then keeps every signal blocked, and children spawned from then on start withSIGINTblocked. For a terminal child, writing\x03still generatesSIGINTin the kernel, but the foreground program never acts on it. Terminal writes themselves were fine, which made this look like a lost-input bug.The fix uses
pthread_sigmaskfor the save, block and restore, and for the child's mask beforeexec.pthread_sigmaskis per-thread on every platform. On Linux, glibc and musl already implementsigprocmaskper-thread, so behavior there is unchanged. Upstream Bunmainstill callssigprocmaskhere.How did you verify your code works?
macOS arm64 release build of this branch on
openclaw/main8282146:terminal-spawn.test.tscase "concurrent Worker terminals preserve child signal masks": two Workers, gated withAtomicsso their spawns overlap, each spawn 8 terminal children, send\x03, and wait for the child'sINTtrap. It times out on the unfixed release build and passes on this one. With the fix it passed 3/3 runs. The original two-worker repro passed 56 iterations per worker.test/js/bun/terminal/plusspawn,spawn-signal, andexit-code: 323 pass, 29 skip, 0 fail. An earlier run of the same set on a machine at load average about 37 (another Bun build running) hit the 5 s default timeout in the existing "ESRCH while a terminal child exits" case from fix(spawn): avoid blocking macOS ESRCH exit waits #11. Rerun alone at the same load, it passed in 0.4 to 1.1 s, and the next full run was clean, so it is load-sensitive and unrelated to this change.