Repository navigation
Description
TL;DR
A worker shares the foreground process group of its client, so Ctrl-C in the
REPL reaches the worker too. _ignore_terminal_interrupts stops the worker
dying of it. No test covers that, and only an ad-hoc tmux run found the
original defect.
The guard needs no terminal emulator and no debugger. It needs two
assertions: the worker really is in the blast radius, and it survives the
blast.
Evidence
worker_service_factory calls _ignore_terminal_interrupts(), which sets
SIGINT to SIG_IGN. Before it, asyncio.Runner installed a SIGINT handler
that cancelled the main task and re-raised KeyboardInterrupt, which ended
the worker. The REPL cancelled its evaluation and returned to its prompt with
a dead worker behind it, over a grpclib traceback.
Removing that call today turns no test red. A double cannot find the defect,
because the defect is about a real process group and a real signal.
Scope
One test, beside the existing worker-process tests in
tests/nanopynix/rpc/client/test_workerpool.py, which already reach
nix._manager._worker_proc.
assert os.getpgid(worker_pid) == os.getpgid(0) # the precondition
os.kill(worker_pid, signal.SIGINT) # the defence
assert await (await ev.string("1 + 1")).to_python() == 2The precondition assertion is what makes the second one mean something: it
says the worker is in the group a terminal signals, so surviving a direct
SIGINT is the property that matters rather than a coincidence.
Signal the worker directly rather than the process group. killpg would also
signal pytest, and the pair of assertions above already proves the whole
causal chain without that risk.
Rejected alternatives
- A pty plus
pyte. A pty is only a way to make the tty line discipline
callkillpg. A test can signal directly.pyteearns a place only for
what the user sees -- the echoed^C, the prompt returning -- which is
cosmetic and belongs in its own issue. libtmux. The same fidelity as a pty, plus an external process and an
IPC protocol in the test path. Useful by hand, not in CI.- PEP 768
sys.remote_exec. Present on CPython 3.14, and a poor fit. It
runs only at a safe eval-loop point, and the states of interest are exactly
when the worker is blocked inside Nix.ptrace_scopeis 1, and the
forkserver means pytest is not the worker's parent. - A
multiprocessingmanager. A second RPC channel beside the gRPC one
the worker already serves.
To inspect worker state, extend the in-process harness in
tests/nanopynix/rpc/test_l3_inproc.py, which runs the real handlers in the
test process. That is where arbitrary introspection is free.
Acceptance criteria
- The new test passes, and fails when
_ignore_terminal_interruptsis
removed. Show both. - No new dependency.
Refs #66
Activity
test(rpc): guard the worker against a terminal interrupt