Relationships
#4885 serve --json --exit-on-stdin-close never exits when its host is SIGKILLed while a run is in flight
Opened by zack · 11/18/2026· Shipped 11/18/2026
Description
When the process holding a swamp serve --json --exit-on-stdin-close child's stdin, stdout and stderr is SIGKILLed while a run is in flight, serve begins shutting down but never exits. It keeps running indefinitely and keeps its port. That is exactly the case --exit-on-stdin-close exists for (swamp-club#4797): "a host that dies for any reason (SIGKILL included) closes the pipe and its children stop". The real serve host spawns its children this way: src/serve/host/serve_process.ts:95-107 passes serve --json … --exit-on-stdin-close and pipes all three streams.
Steps to reproduce
- Run
swamp initand add a workflow with a shell step runningsleep 5. - Start
swamp serve --json --no-schedule --exit-on-stdin-close --webhook /s:<wf>:<secret>with stdin, stdout and stderr on FIFOs held by one holder process. - Send a signed webhook POST to start a run, wait 1.5 s, then SIGKILL the holder.
Expected
Serve drains the run and exits 0 on its own.
Actual
/readyanswers 503shutting_down, and the run succeeds.- Serve is still alive more than 40 s later, still holding fds 0, 1 and 2.
- No
stoppingorstoppedline is written.
Controls, all with --json:
- With nothing in flight, serve exits 0.
- With a holder on stdin only, or on stdin and stdout, serve exits 0.
- With a holder on stdin and stderr, serve hangs.
- Without
--json, serve exits 0.
strace shows write(2, "{\"status\":\"stopping\"}\n", 22) = -1 EPIPE (Broken pipe), with no further shutdown output after it.
Root cause (from source)
shutdown()insrc/cli/commands/serve.ts(around lines 8369-8397) setsshuttingDown, then callsconsole.log(JSON.stringify({status:"stopping"}))before the drain.- While a method runs, the console guard (
src/domain/models/console_guard.ts:40,186-191) sends that line toDeno.stderr.writeSync. This is swamp-club#4884. - With no reader on stderr,
writeSyncthrows BrokenPipe. Deno ignores SIGPIPE, so this surfaces as an exception, and nothing catches it. - The exception rejects
shutdown().watchStdinClose(src/serve/stdin_close_trigger.ts:39-45) and the signal handler (aroundserve.ts:8703-8709) only log "Shutdown error" to the same broken stderr. The memoized shutdown run blocks any retry.
Fix: write the lifecycle line without the guard. Beyond that, the guarded stderr writer, and shutdown's status writes generally, should tolerate a closed stderr, so shutdown always carries on to the drain and exit.
Environment
- swamp built from main
8b8e14c6, Linux. - Found by the swamp-uat test
tests/cli/serve/none/exit_on_stdin_close_test.ts: "swamp serve --exit-on-stdin-close drains an in-flight run and exits 0 when the host holding its pipes is killed outright" (swamp-uat#975).
Shipped
Click a lifecycle step above to view its details.
Sign in to post a ripple.