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
err_fail's _exit and stdio leave an embedder no fatal path (terminal state, signals) #1624
A native program's fatal path gives an embedder no way to undo shared state it changed, such as a terminal's termios. err_fail (bend2/comp.ts:3726 on main at 234cb9b) does:
It is reached from about 30 places (a deadlock, an out-of-memory in io_mem, a failed reservation or pthread_create, ...) and from err_trap, the SIGSEGV/SIGBUS handler installed with sigaction (comp.ts:4726-4728).
Why it matters
_exit skips atexit, so an effect that put the terminal in raw mode (our Tty.raw_on, a C effect) cannot restore it: after a runtime deadlock or memory fault the user's shell is left raw.
The runtime catches SIGSEGV/SIGBUS itself and turns them into _exit(1), so a host cannot catch those signals either: a crash looks like a plain exit 1.
fflush/fprintf are not async-signal-safe, and err_trap runs them from a signal handler (a fault while another thread holds the stdio lock can hang the process instead of ending it).
What we do now
A small supervisor process that saves the termios, runs the Bend program, waits for it and restores (it covers SIGKILL too). That works, but it costs a second process; an in-process fatal path would let simpler embedders stay correct.
Possible changes (any one would help)
A documented fatal hook: a C function an effect registers, called by err_fail before _exit, with the contract that it must be async-signal-safe.
write(2) instead of stdio in err_fail (async-signal-safe), and, for err_trap, re-raise the original signal with its default action after the message, so the process ends by SIGSEGV/SIGBUS and a parent sees the real cause.
Version / system
Bend v2.0.35 (we pin it); checked the same code on main at 234cb9b. Darwin arm64.
The trap is async-signal-safe now (#1655) and memory faults end by their real signal (#1828), so a parent sees the cause. We're not adding a fatal hook (#1929): one runtime slot can't serve several effects. An effect that changes shared state can guard itself with a guardian process that restores it when the program dies, which also covers SIGKILL; your supervisor does the same from outside.
Activity
fix(runtime): make the SIGSEGV/SIGBUS trap async-signal-safe
fix(runtime): make the SIGSEGV/SIGBUS trap async-signal-safe
fix(runtime): make the SIGSEGV/SIGBUS trap async-signal-safe
fix(runtime): make the SIGSEGV/SIGBUS trap async-signal-safe
nicolas-abril commentedon Oct 29, 2026
The trap is async-signal-safe now (#1655) and memory faults end by their real signal (#1828), so a parent sees the cause. We're not adding a fatal hook (#1929): one runtime slot can't serve several effects. An effect that changes shared state can guard itself with a guardian process that restores it when the program dies, which also covers
SIGKILL; your supervisor does the same from outside.