fix: exit cleanly when stdout pipe closes early - #65
Draft
posthog[bot] wants to merge 2 commits into
Draft
posthog[bot] wants to merge 2 commits into
posthog[bot] wants to merge 2 commits into
Conversation
Rust ignores SIGPIPE before `main`, so a reader that closes a pipe early (e.g. `autter blame | head`) turned the closed pipe into an EPIPE that made `println!` panic with "failed printing to stdout". Restore the Unix default (SIG_DFL) at the top of `main` so the process exits quietly on a closed pipe, like every other CLI tool. This removes the panic path for every print-heavy subcommand at once. The long-lived daemon re-ignores SIGPIPE (SIG_IGN) at startup so its network and control-socket writes keep returning EPIPE instead of getting killed by a signal. Also record the current subcommand and add it to the panic report context, which previously carried only a source location. Generated-By: PostHog Desktop Task-Id: 30cd172e-097b-4b6e-bce6-c8f73634b434
…g SIGPIPE The first approach reset SIGPIPE to SIG_DFL process-wide. Review found that the CLI (including the transparent git proxy) writes to the daemon control socket on nearly every invocation; under SIG_DFL a daemon that closed the socket mid-write would deliver SIGPIPE and silently kill the command, bypassing the existing reconnect/retry logic. A daemon-only re-ignore did not cover those CLI-side writers. Keep SIGPIPE ignored (Rust's default, network-safe everywhere) and instead recognize the broken-pipe panic from the print macros in the panic hook and exit quietly (exit 0), without printing a panic or reporting telemetry. This fixes the same symptom (`autter blame | head`) centrally, leaves every socket write's EPIPE handling intact, and keeps the existing BrokenPipe handling in log.rs working as written. Also dedup: route the test helpers autter_with_env/autter_with_stdin through the new autter_command, and compute the git subcommand once in handle_git. Generated-By: PostHog Desktop Task-Id: 30cd172e-097b-4b6e-bce6-c8f73634b434
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.
Problem
auttersubcommand into a reader that closes early —autter blame | headis the everyday case — crashed the CLI with a panic instead of exiting quietly. The user saw a stack trace where they expected output, and each crash added noise to error tracking.SIGPIPEto ignore beforemain, so when the pipe reader closes, the next write returnsEPIPEand the plainprintln!/print!macro panics withfailed printing to stdout: Broken pipe. The panic points at Rust's ownlibrary/std/src/io/stdio.rs, confirming the macro — not any one command — is at fault. Most subcommands print this way (blame,config,status,onboard,autter_handlers).Changes
src/observability/mod.rs— the panic hook now recognizes the broken-pipe panic from the print macros and exits quietly (exit 0), without printing a panic or reporting telemetry. One central fix covers everyprintln!site in every subcommand.SIGPIPEtoSIG_DFL? That was the first attempt.autteris also its own daemon: the CLI (including the transparent git proxy) writes to the daemon control socket on nearly every invocation. UnderSIG_DFL, a daemon that closed the socket mid-write would deliverSIGPIPEand silently kill the command, bypassing the existing reconnect/retry logic — a worse regression than the bug being fixed. KeepingSIGPIPEignored (Rust's default) leaves every socket write'sEPIPEhandling intact and keeps the existingBrokenPipehandling inlog.rsworking as written.Test plan
broken_pipe::blame_into_closed_pipe_does_not_panic: runsautter blameon a large file into a pipe whose reader closes after 64 bytes, then asserts the process exits cleanly (exit 0), with no panic on stderr.failed printing to stdout: Broken pipeatlibrary/std/src/io/stdio.rs) — and passes with it.cargo buildandcargo clippyclean for the changed code.Agent context
SIG_DFLreset (plus a daemonSIG_IGNcounter-measure); a review pass found the CLI-side control-socket writers were left exposed to a silentSIGPIPEkill, so the approach was changed to the central panic-hook interception above.log::log_plain_rejects_http_backendfails onmainalready (its expected message string does not match the code's) — pre-existing and unrelated to this change; left untouched.Created with PostHog Desktop from this inbox report.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.