From ca0b1b2f455db99d8f59743e06904a1624379dca Mon Sep 17 00:00:00 2001 From: ohcohen Date: Sun, 15 Nov 2026 12:41:28 +0200 Subject: [PATCH 1/3] fix: forward SIGQUIT to the command's process group Closes #40 --- docs/adr/0001-leeway.md | 4 ++-- packages/leeway/README.md | 3 ++- packages/leeway/src/os/run-with-ports.ts | 2 +- packages/leeway/test/cli.test.ts | 29 +++++++++++++----------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/docs/adr/0001-leeway.md b/docs/adr/0001-leeway.md index 186af94..23bfba3 100644 --- a/docs/adr/0001-leeway.md +++ b/docs/adr/0001-leeway.md @@ -97,8 +97,8 @@ shell line with it fails rather than lose its quotes. **Environment variables are the transport.** They pass through `concurrently`, `tsx`, package scripts and shells to every child process with no integration. `leeway` runs the command through the system shell: one argument is a shell line, several are an argv quoted for -the shell. Stopping leeway stops the tree: on POSIX the command gets its own process group and SIGINT, SIGTERM and SIGHUP are forwarded to -it; on Windows, which has no process groups to signal, Ctrl+C, Ctrl+Break and console close run `taskkill /T /F`. +the shell. Stopping leeway stops the tree: on POSIX the command gets its own process group and SIGINT, SIGTERM, SIGHUP and SIGQUIT are +forwarded to it; on Windows, which has no process groups to signal, Ctrl+C, Ctrl+Break and console close run `taskkill /T /F`. **Browser and vite.** `devPorts` is browser-safe. `leeway/vite` sets `server.port` and `preview.port` with `strictPort`, so a taken port fails instead of drifting. `preview.port` uses the dev server's port name unless `preview` names another: left alone, vite previews on diff --git a/packages/leeway/README.md b/packages/leeway/README.md index 13391cc..0ae225f 100644 --- a/packages/leeway/README.md +++ b/packages/leeway/README.md @@ -209,7 +209,8 @@ folder still claims its own range, and an explicit `--default` or `--inherit` ke - The command runs through the system shell (`sh`, `cmd.exe` on Windows). - leeway exits with the shell's exit code (a missing command: 127 from `sh`, 1 from `cmd.exe`; a command killed by a signal: usually 128 plus the signal number from `sh`), or 1 if the shell itself died from a signal or could not start. -- Stopping leeway (Ctrl+C, a signal, closing the terminal) stops the whole command tree. +- Stopping leeway stops the whole command tree: on Linux and macOS Ctrl+C, Ctrl+\, closing the terminal, or SIGINT, SIGTERM, SIGHUP or + SIGQUIT; on Windows Ctrl+C, Ctrl+Break or closing the console. `leeway --help` (or `-h`) prints the usage, `leeway --version` the version. diff --git a/packages/leeway/src/os/run-with-ports.ts b/packages/leeway/src/os/run-with-ports.ts index 619d57c..7b0279c 100644 --- a/packages/leeway/src/os/run-with-ports.ts +++ b/packages/leeway/src/os/run-with-ports.ts @@ -3,7 +3,7 @@ import { ProcessTree } from "./process-tree.ts"; const WINDOWS_STOP_SIGNALS: NodeJS.Signals[] = ["SIGINT", "SIGBREAK", "SIGHUP"]; -const POSIX_FORWARDED_SIGNALS: NodeJS.Signals[] = ["SIGINT", "SIGTERM", "SIGHUP"]; +const POSIX_FORWARDED_SIGNALS: NodeJS.Signals[] = ["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT"]; export class RunWithPorts { static runAndExit(commandLine: string, env: Record): void { diff --git a/packages/leeway/test/cli.test.ts b/packages/leeway/test/cli.test.ts index 2c04339..11c0a41 100644 --- a/packages/leeway/test/cli.test.ts +++ b/packages/leeway/test/cli.test.ts @@ -563,19 +563,22 @@ describe("leeway errors", () => { }); describe.skipIf(process.platform === "win32")("leeway on a signal", () => { - it.each(["SIGINT", "SIGTERM", "SIGHUP"] as const)("%s stops the whole command tree, so nothing is left listening", async signal => { - const { dir, home } = temporaryFolder(); - const leeway = startLeeway(["node", "launcher.mjs"], dir, home); - const port = await listeningPort(leeway); - const exitCode = new Promise(resolve => leeway.once("exit", resolve)); - - expect(await answers(port)).toBe(true); - - leeway.kill(signal); - - expect(await exitCode).not.toBe(0); - expect(await stopsAnswering(port)).toBe(true); - }); + it.each(["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT"] as const)( + "%s stops the whole command tree, so nothing is left listening", + async signal => { + const { dir, home } = temporaryFolder(); + const leeway = startLeeway(["node", "launcher.mjs"], dir, home); + const port = await listeningPort(leeway); + const exitCode = new Promise(resolve => leeway.once("exit", resolve)); + + expect(await answers(port)).toBe(true); + + leeway.kill(signal); + + expect(await exitCode).not.toBe(0); + expect(await stopsAnswering(port)).toBe(true); + }, + ); }); describe.runIf(process.platform === "win32")("leeway on Ctrl+C in its console", () => { From f876b04e205a35a82d0d71db78a7413965c551e7 Mon Sep 17 00:00:00 2001 From: ohcohen Date: Sun, 15 Nov 2026 12:42:17 +0200 Subject: [PATCH 2/3] docs: tidy the stopping line in the README --- packages/leeway/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/leeway/README.md b/packages/leeway/README.md index 0ae225f..bdf8a73 100644 --- a/packages/leeway/README.md +++ b/packages/leeway/README.md @@ -209,8 +209,8 @@ folder still claims its own range, and an explicit `--default` or `--inherit` ke - The command runs through the system shell (`sh`, `cmd.exe` on Windows). - leeway exits with the shell's exit code (a missing command: 127 from `sh`, 1 from `cmd.exe`; a command killed by a signal: usually 128 plus the signal number from `sh`), or 1 if the shell itself died from a signal or could not start. -- Stopping leeway stops the whole command tree: on Linux and macOS Ctrl+C, Ctrl+\, closing the terminal, or SIGINT, SIGTERM, SIGHUP or - SIGQUIT; on Windows Ctrl+C, Ctrl+Break or closing the console. +- Stopping leeway stops the whole command tree: Ctrl+C, Ctrl+\, closing the terminal, or SIGINT, SIGTERM, SIGHUP + or SIGQUIT on Linux and macOS; Ctrl+C, Ctrl+Break or closing the console on Windows. `leeway --help` (or `-h`) prints the usage, `leeway --version` the version. From 3331d696aaa75079367ebeb47c85ea5edcd39b12 Mon Sep 17 00:00:00 2001 From: ohcohen Date: Sun, 15 Nov 2026 12:51:49 +0200 Subject: [PATCH 3/3] docs: a command that handles a signal and keeps running outlives leeway --- packages/leeway/README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/leeway/README.md b/packages/leeway/README.md index bdf8a73..107ceea 100644 --- a/packages/leeway/README.md +++ b/packages/leeway/README.md @@ -209,8 +209,9 @@ folder still claims its own range, and an explicit `--default` or `--inherit` ke - The command runs through the system shell (`sh`, `cmd.exe` on Windows). - leeway exits with the shell's exit code (a missing command: 127 from `sh`, 1 from `cmd.exe`; a command killed by a signal: usually 128 plus the signal number from `sh`), or 1 if the shell itself died from a signal or could not start. -- Stopping leeway stops the whole command tree: Ctrl+C, Ctrl+\, closing the terminal, or SIGINT, SIGTERM, SIGHUP - or SIGQUIT on Linux and macOS; Ctrl+C, Ctrl+Break or closing the console on Windows. +- Stopping leeway stops the whole command tree: Ctrl+C, `Ctrl+\`, closing the terminal, or SIGINT, SIGTERM, SIGHUP + or SIGQUIT on Linux and macOS; Ctrl+C, Ctrl+Break or closing the console on Windows. On Linux and macOS the tree gets the signal + leeway got, so a command that handles it and keeps running is not stopped ([Limits](#limits)). `leeway --help` (or `-h`) prints the usage, `leeway --version` the version. @@ -493,6 +494,8 @@ eval "$(npx leeway env --export)" it still reads keys from stdin, but tools that open `/dev/tty` directly (some password prompts, full-screen TUIs) fail. - Ctrl+Z on Linux and macOS suspends `leeway` alone: the command, in its own session, keeps running on its ports. `fg`, then Ctrl+C, stops it. +- On Linux and macOS a command that handles a signal and keeps running can outlive `leeway` and stay on its ports: a JVM prints a + thread dump on `Ctrl+\` and carries on, while the `sh` above it dies and `leeway` exits. `leeway kill` stops it. - `nohup leeway ` doesn't outlive the terminal: `leeway` still gets the hangup and stops the command tree. In bash or zsh, use `leeway > leeway.log 2>&1 & disown` instead. - On Windows, Ctrl+C force-kills the command tree at once, so a command that cleans up on Ctrl+C may die before it finishes. Run such a