Skip to main content
← Back to list
01Issue
BugShippedSwamp CLIPublic
Assigneeszack

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

  1. Run swamp init and add a workflow with a shell step running sleep 5.
  2. 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.
  3. 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

  • /ready answers 503 shutting_down, and the run succeeds.
  • Serve is still alive more than 40 s later, still holding fds 0, 1 and 2.
  • No stopping or stopped line 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)

  1. shutdown() in src/cli/commands/serve.ts (around lines 8369-8397) sets shuttingDown, then calls console.log(JSON.stringify({status:"stopping"})) before the drain.
  2. While a method runs, the console guard (src/domain/models/console_guard.ts:40, 186-191) sends that line to Deno.stderr.writeSync. This is swamp-club#4884.
  3. With no reader on stderr, writeSync throws BrokenPipe. Deno ignores SIGPIPE, so this surfaces as an exception, and nothing catches it.
  4. The exception rejects shutdown(). watchStdinClose (src/serve/stdin_close_trigger.ts:39-45) and the signal handler (around serve.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).
02Bog Flow
✓OPEN✓TRIAGED✓IN PROGRESS✓SHIPPED+ 1 MOREASSIGNED+ 2 MOREREVIEW+ 10 MOREPR_LINKED+ 2 MORESESSION_SUMMARIZED

Shipped

11/18/2026, 10:10:34 PM

Click a lifecycle step above to view its details.

03Sludge Pulse
zack assigned zack11/18/2026, 9:17:32 PM

Sign in to post a ripple.