You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(native): run effect cleanup before fatal exit - #1929
This fills the cleanup gap left after #1655 and #1828: native effect constructors can set err_cleanup, and the first fatal claimant runs it before exiting. The hook must be async-signal-safe. It doesn’t recover the program or swallow its original signal.
I checked this with real PTYs on Linux and macOS arm64. Before the change, failstop/SIGSEGV/SIGBUS left the terminal raw; afterwards, its configuration is restored and the exit/signal stays the same. Normal exit is a separate control. macOS before/after and stack-fault run.
The native consumer also covers one-shot cleanup and a fault inside the hook; it passed through native, Bun and Node on Linux. The existing stack-fault case still terminates by signal on both OSes.
Repo gate: 54/54. Compiler: 65,992/66,000 tokens, with no budget or gate changes.
Thanks, and the PTY checks on both OSes are thorough. We're not taking a runtime cleanup slot, though. err_cleanup is a single pointer set in a constructor, so two effects that each need cleanup can't both register (constructor order decides, silently), and the hook is armed whether or not the effect ever ran. A fatal stop is a bug or resource exhaustion, and an effect that changes shared state can guard itself without the runtime's help. For example, raw_on can fork a small guardian that holds the saved termios and blocks on a pipe. When the program dies, by err_fail, a signal or even SIGKILL, the pipe closes and the guardian restores the terminal. Effects compose that way, and it covers more than an async-signal-safe hook can. An external supervisor, as #1624 describes, works too.
Got it. A single slot is not composable, and a runtime hook cannot cover SIGKILL anyway. I’ll drop this approach rather than turn it into a cleanup registry. The guardian/supervisor belongs with the effect or embedder; I’m not treating this closed PR as a fix for #1624.
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
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.
Closes #1624.
This fills the cleanup gap left after #1655 and #1828: native effect constructors can set
err_cleanup, and the first fatal claimant runs it before exiting. The hook must be async-signal-safe. It doesn’t recover the program or swallow its original signal.I checked this with real PTYs on Linux and macOS arm64. Before the change, failstop/SIGSEGV/SIGBUS left the terminal raw; afterwards, its configuration is restored and the exit/signal stays the same. Normal exit is a separate control. macOS before/after and stack-fault run.
The native consumer also covers one-shot cleanup and a fault inside the hook; it passed through native, Bun and Node on Linux. The existing stack-fault case still terminates by signal on both OSes.
Repo gate: 54/54. Compiler: 65,992/66,000 tokens, with no budget or gate changes.