[Unix] Forward signals to pre-installed handlers + add --handle-signals=minimal#61294
Open
topolarity wants to merge 3 commits intoJuliaLang:masterfrom
Open
[Unix] Forward signals to pre-installed handlers + add --handle-signals=minimal#61294topolarity wants to merge 3 commits intoJuliaLang:masterfrom
--handle-signals=minimal#61294topolarity wants to merge 3 commits intoJuliaLang:masterfrom
Conversation
5e4b094 to
d44e418
Compare
In theory, this significantly improves our Julia-as-a-library behavior by allowing Julia to forward signals to other copies of the Julia runtime, or an outer application that may have loaded us. Covers all fault handlers: SIGSEGV, SIGBUS, SIGFPE, SIGILL, SIGABRT, SIGSYS, SIGTRAP as well as SIGUSR2 Also adds forwarding for SIGINT, SIGTERM, SIGQUIT, SIGINFO, and SIGUSR1 although these `sigwait()`'d signals will typically be blocked anyway so that forwarding will not happen.
d44e418 to
d723429
Compare
d723429 to
0ba751d
Compare
This adds a `--handle-signals=minimal` option to restrict Julia to installing only those signals that are essential to its operation and which we can reliably forward to outer / pre-existing handlers. The signals excluded are generally the "I/O"-like signals, incl. SIGINT, SIGUSR1/2, SIGINFO, and SIGTERM / SIGQUIT and received by `sigwait()` which cannot forward signals to a competing `sigwait()` loop anyway. For an end user, this means that Julia will not respond to `Ctrl-C`, SIGTERM / SIGQUIT (requests to terminate), or support in-process profiling. This is appropriate behavior for a library, which should typically defer these signals to the overall application anyway.
31a009d to
4bf21ac
Compare
This test checks the "sweet spot" we're interested in: - Installed handlers can reliably forward signals - Installed handlers are sufficient for GC + multi-threading --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
4bf21ac to
9392332
Compare
--handle-signals=min)--handle-signals=minimal)
Draft
2 tasks
--handle-signals=minimal)--handle-signals=minimal
9 tasks
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.
This adds a
--handle-signals=minoption to restrict Julia to installing only those signals that are:The most important of these is our SIGSEGV / SIGBUS handler (used by the GC as a safepoint trigger), but this also changes divide-by-zero, SIGILL, and similar faults to prefer forwarding these to a previously installed handler, if one was found, rather than immediately throwing an exception in Julia.
This is intended to be used in a "Julia as a library" scenario.
From a user's perspective the limitations of "minimal" signal handling are:
Ctrl-CsignalsProfile.@profile) is not supportedSIGTERM/SIGQUITDivideError(and similar) exceptions despite triggering a faultIn the future, it may be a good idea to keep a stricter notion of "execution state" on each thread, so that Julia can distinguish, e.g., a
DivideErrorfault in its own code vs. faults in other libraries (or parallel copies of the Julia runtime).Python handles this "thread attach / detach" via
PyGILState_Ensure/PyGILState_Releaseand Java does this viaAttachCurrentThread/DetachCurrentThreadand of course Windows has the SEH stack but the Julia API has no equivalent (jl_adopt_thread/jl_destroy_threadare called based on the thread lifetime, not the active execution state).P.S. This is Linux / BSD-only as is. macOS will need additional work, since forwarding mach exceptions is somewhat more complicated.
Co-developed with Claude.