Skip to content

fix(rocm): reset SIGPIPE so --dry-run doesn't panic (rc=101) - #185

Open
fredespi wants to merge 2 commits into
mainfrom
rocm-fix-fix-2-unset-override-dry-run-panics-rc
Open

fix(rocm): reset SIGPIPE so --dry-run doesn't panic (rc=101)#185
fredespi wants to merge 2 commits into
mainfrom
rocm-fix-fix-2-unset-override-dry-run-panics-rc

Conversation

@fredespi

@fredespi fredespi commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

rocm fix fix-2-unset-override --dry-run panicked with rc=101 when its output was piped — a dry-run should never panic. Rust ignores SIGPIPE by default and converts a broken pipe into a panic; this resets the SIGPIPE handler to default so piped output terminates cleanly.

Changes

  • Reset SIGPIPE to SIG_DFL at startup so a closed pipe exits normally (repro now exits 141, not a 101 panic).
  • Added a regression test for the piped dry-run path.

Test plan

  • Repro (... --dry-run | head) no longer panics — exits 141.
  • Regression test passes; clippy + unit/lib tests green in the container.

@fredespi
fredespi requested a review from a team as a code owner August 6, 2026 03:55
Rust installs SIG_IGN for SIGPIPE at startup, so when a downstream reader
closes the pipe early (e.g. `rocm fix … --dry-run | head`) the next
println! panics with "failed printing to stdout: Broken pipe" and exits
101. Reset SIGPIPE to SIG_DFL at the top of main() (the ripgrep/fd
pattern) so the process terminates on the signal like a conventional Unix
CLI. Socket writes are unaffected: std uses MSG_NOSIGNAL, so serve/daemon
paths still get a normal BrokenPipe error.

Adds a regression test that closes stdout early on a large-output command
and asserts no panic / not exit 101.

Signed-off-by: fredespi <fredrik.espinoza@gmail.com>
The process-wide SIG_DFL reset makes stdout/stderr pipe writes terminate
conventionally, but it also affects the one place rocm writes to a spawned
child's stdin: the engine stdio request. If an engine exits before reading
its stdin, that write would kill rocm with SIGPIPE before the exit-status
diagnostics can run. Wrap the write in with_sigpipe_ignored() so it returns
EPIPE (surfaced as a normal error) instead of a signal; socket MSG_NOSIGNAL
does not cover ChildStdin pipes.

Adds a re-exec'd regression test that, under SIG_DFL, asserts an unguarded
write to a dead child's stdin is killed by SIGPIPE while the guarded write
survives with an error.

Signed-off-by: fredespi <fredrik.espinoza@gmail.com>
@fredespi
fredespi force-pushed the rocm-fix-fix-2-unset-override-dry-run-panics-rc branch from 09e1c08 to 9291469 Compare August 6, 2026 12:43
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.

2 participants