fix(python): keep SIGINT fatal while the core runs - #1165
Merged
Merged
Conversation
The launcher's colocated test now expects the default disposition, and a new e2e case blocks the scan in an `on-file` hook and asserts the process dies of the signal. skip-changelog: tests only
The launcher's empty handler could never be replaced by a Python callable that exits, because the core detaches the GIL for the whole of `run_cli` and no Python handler reaches the eval loop until it returns. SIG_DFL is the only disposition the kernel acts on unaided, and signal-hook still overrides it for the `dirsql server` window, so graceful shutdown keeps its exit code.
8 tasks done
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.
Fixes #1164
Problem
packages/python/dirsql/cli/main.pyinstalled_absorb_interrupt, an empty SIGINT handler, for the wholerun_cliwindow, on the reasoning that the core "returns promptly for every non-server command". A directory scan does not, so Ctrl-C was swallowed and the process was SIGTERM-only.Why the TypeScript shape does not port
keep-signals-fatal.tsregisters a JS listener thatprocess.exit(130). The Python equivalent -- any Python callable -- cannot run at all while the core is working:run_clidetaches the GIL for its entire duration, so no Python-level handler reaches the eval loop until the scan has already finished.Measured, with the launcher blocked in an
on-filehook (sleep 120):run_clidirsql servergraceful shutdown_absorb_interrupt(before)default_int_handler(no launcher install)signal.SIG_DFL(this PR)So
default_int_handleris not a fix either -- it merely trades a swallowed signal for a swallowed signal plus a broken server exit code.SIG_DFLis the only disposition the kernel can act on without the interpreter, and it is exactly what the standalone binary runs with.Why
dirsql serverdoes not regresssignal-hook (which tokio uses) replaces the disposition when
run_serverregisters its handlers, and does not re-raiseSIG_DFLon the way out -- so during the server window the core's own graceful shutdown is the only thing that acts, and its exit code survives. That is the same chain the standalone binary has, and the measurements above confirm it: exit 0, three runs out of three.The REPL is unaffected: reedline puts the terminal in raw mode, which disables
ISIG, so Ctrl-C arrives as a key event and never as a signal. Verified under a pty with a DSR responder -- Ctrl-C returns a fresh prompt and the process stays alive, identically before and after.Scope: the other two launchers
Both were checked rather than assumed.
serverexits 0. No handler is needed on the Rust query path. (A caveat for anyone re-running this: a non-interactive shell sets SIGINT toSIG_IGNfor&background jobs, which makes the binary look immune. Reset the disposition in the spawner before testing.)runCliis a synchronous napi export, so it blocks the Node event loop andkeepSignalsFatal's JS listener cannot run either. Probed directly against the built addon with both listeners registered: SIGINT mid-scan is swallowed and the listener never fires. Filed as Ctrl-C does not interrupt a running query in the npm launcher #1166 rather than widening this PR; Node has noSIG_DFLequivalent reachable from JS, so the fix is a different shape.Changelog / Migrations
<root>/<pkg>/changelog.d/for each changed package (or:skip-changelogtrailer on a commit with reason)<root>/<pkg>/migrations.d/(or: not required -- additive/bugfix only)E2E Verification
packages/rustchange)packages/python/e2e-attestations/claude-1164-sigint-fatal.jsonreceipt written (just e2e-attest-python)packages/ts/e2e-attestations/<branch>.jsonreceipt written ifpackages/tschanged (just e2e-attest-ts) -- N/Acd packages/python && uv run python -m pytest tests/e2e/ -x -q, viajust e2e-attest-pythonsigint_interrupt_test.py.By-hand check
Against a real 240,000-file tree under
/tmp(not$HOME), no hook, no fixture:And the server, same launcher, same session: banner printed,
kill -INT->exit=0.