Update on Deno Watch Mode Signal Issue.
Source: Dev.to
There is an issue in Deno where the signal handler doesn’t work in watch mode. I believe this happens because the Deno file watcher doesn’t send the INT signal to the worker, causing it to just stop instead. I’m confident about this now.
Source in Deno
select! {
_ = receiver_future => {},
_ = deno_signals::ctrl_c() => {
return Ok(()); // this line handled the INT signal and fulfilled select!
},
_ = restart_rx.recv() => {
print_after_restart();
continue;
},
success = operation_future => { /* ... */ }
}
In the Deno code, the select! statement acts like JavaScript’s Promise.any. It completes as soon as the INT signal is ignored. The operation_future runs the user’s JavaScript or TypeScript files, but it doesn’t get a chance to activate the user‑defined listener.
How Node.js Handles Signals in Watch Mode
Node.js sends the signal to the worker and waits for the worker to finish.
async function killAndWait(signal = kKillSignal, force = false) {
child?.removeAllListeners();
if (!child) {
return;
}
if ((child.killed || exited) && !force) {
return;
}
const onExit = once(child, 'exit');
child.kill(signal);
const { 0: exitCode } = await onExit;
return exitCode;
}
Proposed Approach for Deno
I plan to adopt a similar strategy: send the signal to the worker to trigger the listener and then wait for it to complete. This should allow user‑defined signal handlers to run correctly in watch mode.