diff --git a/CHANGELOG.md b/CHANGELOG.md index 06cf6da..c68d14c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All user-visible bugs and enhancements should be recorded here. ## Unreleased +### Fixed + +- Stopping the npm `xurl` command now stops the xurl binary too. The npm wrapper started the binary without passing on termination signals, so when a process supervisor or MCP host stopped it (for example to restart `xurl mcp`), the binary kept running detached with the host's input and output still open. The wrapper now forwards SIGINT, SIGTERM, SIGHUP and SIGQUIT and exits with the binary's exit code or signal. + ## v1.3.4 - 2026-09-29 ### Fixed diff --git a/npm/cli.js b/npm/cli.js index 7ee631c..a188740 100755 --- a/npm/cli.js +++ b/npm/cli.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -const { execFileSync } = require("child_process"); +const { spawn } = require("child_process"); const path = require("path"); const fs = require("fs"); @@ -11,8 +11,34 @@ if (!fs.existsSync(binary)) { process.exit(1); } -try { - const result = execFileSync(binary, process.argv.slice(2), { stdio: "inherit" }); -} catch (e) { - process.exit(e.status || 1); +// Run the binary as a child we can signal. A supervisor that stops this wrapper +// (an MCP host restarting `xurl mcp`, a process manager, Ctrl+C) must stop the +// binary too, or it keeps running detached with the host's stdio pipes open. +const child = spawn(binary, process.argv.slice(2), { stdio: "inherit" }); + +const forwarded = ["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT"]; +const relay = (signal) => { + if (child.exitCode === null && child.signalCode === null) child.kill(signal); +}; +for (const signal of forwarded) { + try { + process.on(signal, relay); + } catch (e) { + // Not every signal can be listened for on every platform. + } } + +child.on("error", (e) => { + console.error(`xurl: could not start ${binary}: ${e.message}`); + process.exit(1); +}); + +child.on("exit", (code, signal) => { + if (signal) { + // End the same way the binary did, so callers see the same exit status. + for (const s of forwarded) process.removeListener(s, relay); + process.kill(process.pid, signal); + return; + } + process.exit(code === null ? 1 : code); +});