Skip to content

fix(broker-v2): a closed stdout should not kill the broker - #843

Merged
zackees merged 1 commit into
mainfrom
fix/broker-v2-survives-closed-stdout
Aug 2, 2026
Merged

zackees merged 1 commit into
mainfrom
fix/broker-v2-survives-closed-stdout

Conversation

@zackees

@zackees zackees commented Aug 2, 2026

Copy link
Copy Markdown
Owner

The v2 broker dies with a panic if nobody is reading its stdout. This stops that, and adds the test that holds it.

The bug, and how I know it is confusing

println! panics when its write fails. The failure it meets in practice is EPIPE — whoever was reading stdout stopped. The broker then exits 101, and the backtrace points at the logging line. The log statement is the bystander; the closed pipe is the cause.

I know that is misleading because it misled me. During the #532 acceptance work a test reader broke out of its loop after the bound-path line, closing the pipe. The broker's shutdown message hit EPIPE. I concluded the shutdown path was defective and said so on two issues before finding the real cause.

#839 fixed the test, by draining to EOF. That was correct for the test and no fix at all for the binary — a supervisor that closes stdout still kills the broker.

The change

say! and say_err! write through writeln! and drop the error. All 34 call sites move over.

A diagnostic that kills the process when it cannot be delivered is strictly worse than a lost diagnostic. The error is dropped rather than reported because the reporting channel for a failed stdout write is stderr — which, in the case that actually matters (a supervisor closing both), has failed too.

The tradeoff, stated plainly: this also swallows a genuine write failure, such as ENOSPC on a redirected stdout. I think that is right for a log line — the broker's job is brokering, and no part of its correctness depends on the chatter arriving — but it is a trade, not a free win, and a reviewer may reasonably want the ENOSPC case to be loud.

Verification, with a control

The test closes stdout for real: read until the bound path, drop the reader, then require the broker to serve a Hello and shut down cleanly on SIGTERM. Both write to stdout, so both meet the closed pipe.

Passing is not evidence on its own, so I ran the control — reverted the fix and re-ran:

Result
With the fix 8 passed, 0 failed
Fix reverted 1 failed, 7 passed — the new test alone, wait status 25856 (>>8 = 101, a panic)
Restored 8 passed, 0 failed

The failure is the predicted one by exit code, and it is targeted rather than collateral — the other seven tests are unaffected.

Linux via the Docker builder; clippy -D warnings, fmt, spawn-path and cross-compiler guards on Windows.

A trap for anyone running these locally

The linux-debug container cannot run this suite as shipped, for two reasons that compound:

  1. no /etc/machine-id, so user_sid_hash fails and the broker exits before binding
  2. it runs as root, which the broker refuses

Every test in the file then fails identically, which reads exactly like a code regression and is not one. I lost a couple of cycles to it before checking the binary's stderr directly. Supplying a machine-id and RUNNING_PROCESS_BROKER_ALLOW_PRIVILEGED=1 makes them run.

Scope

This closes no issue. It is hardening that came out of #532's acceptance work; #532 itself remains blocked on the handoff-vs-re-dial design decision described in its thread. I am flagging that rather than attaching a convenient issue number to it.

@codecov

codecov Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 30.30303% with 23 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...nning-process/src/bin/running-process-broker-v2.rs 30.30% 23 Missing ⚠️

📢 Thoughts on this report? Let us know!

`println!` panics when the write fails, and the failure it meets in
practice is EPIPE — whoever was reading the broker's stdout stopped.
The broker then exits 101 with a backtrace pointing at the logging
line, which is a misleading thing to hand an operator: the log
statement is the bystander, the closed pipe is the cause.

I know it is misleading because I was misled by it. During the #532
acceptance work a test reader broke out of its loop after the
bound-path line, closing the pipe; the broker's shutdown message hit
EPIPE; and I diagnosed a defect in the shutdown path and said so on
two issues before finding the real cause. #839 fixed the test by
draining to EOF. That was the right fix for the test and no fix at
all for the binary, which still dies if a supervisor closes stdout.

So: `say!` / `say_err!` write through `writeln!` and drop the error.
Diagnostics are best-effort by nature — a diagnostic that kills the
process when it cannot be delivered is strictly worse than a lost
one. The error is dropped rather than reported because the reporting
channel for a failed stdout write is stderr, which in the case that
matters has failed too.

The tradeoff is real and worth naming: this also swallows a genuine
write failure, e.g. ENOSPC on a redirected stdout. I think that is
the right trade for a log line — the broker's job is brokering, and
nothing about its correctness depends on the chatter arriving — but
it is a trade, not a free win.

Tested by closing stdout for real: read until the bound path, drop
the reader, then require the broker to serve a Hello and shut down
cleanly on SIGTERM. Both write to stdout, so both meet the closed
pipe.

Verified on Linux with a control rather than by assertion. With the
fix reverted, that test alone fails, with wait status 25856 (>>8 =
101, a panic) — the exact predicted mechanism — while the other
seven still pass. Restored, 8/8.

One note for whoever runs these locally: the linux-debug container
cannot run them as shipped. It has no /etc/machine-id, so
`user_sid_hash` fails and the broker exits before binding, and it
runs as root, which the broker refuses. Every test in the file fails
identically, which looks like a code regression and is not one.
@zackees
zackees force-pushed the fix/broker-v2-survives-closed-stdout branch from 336a28f to 08ec6fe Compare August 2, 2026 05:41
@zackees
zackees merged commit 5229d38 into main Aug 2, 2026
15 checks passed
@zackees
zackees deleted the fix/broker-v2-survives-closed-stdout branch August 2, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant