Repository navigation
fix(broker-v2): a closed stdout should not kill the broker - #843
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 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
force-pushed
the
fix/broker-v2-survives-closed-stdout
branch
from
August 2, 2026 05:41
336a28f to
08ec6fe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 isEPIPE— 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!andsay_err!write throughwriteln!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
ENOSPCon 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:
25856(>>8= 101, a panic)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-debugcontainer cannot run this suite as shipped, for two reasons that compound:/etc/machine-id, souser_sid_hashfails and the broker exits before bindingEvery 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=1makes 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.