Honor MSG_NOSIGNAL on AF_INET loopback stream send#858
Open
brandonpayton wants to merge 1 commit into
Open
Conversation
`send(fd, buf, MSG_NOSIGNAL)` on a broken connection must return EPIPE without raising SIGPIPE. `sys_send` honored this only on the AF_UNIX branch; the AF_INET loopback path called `sys_write` directly, which unconditionally raises SIGPIPE on a closed pipe. So a loopback TCP server whose peer closed its read side got a spurious SIGPIPE — terminating a process using the default disposition — the exact outcome MSG_NOSIGNAL exists to prevent. This also contradicted the documented guarantee (docs/posix-status.md: "MSG_NOSIGNAL is honored for stream/broken-pipe paths"). Apply the same save/clear-SIGPIPE handling the AF_UNIX branch already uses to the AF_INET loopback path. EPIPE is still returned; only the signal is suppressed. No ABI change. Validation: `cargo test -p kandelo --lib` (964 pass, incl. new `test_send_msg_nosignal_inet_loopback` — a loopback INET connect/accept, close the server end, `send(MSG_NOSIGNAL)`, assert EPIPE and no pending SIGPIPE; verified to fail without the fix). `scripts/check-abi-version.sh` in sync. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Contract: MSG_NOSIGNAL must suppress SIGPIPE on broken streams
send(fd, buf, MSG_NOSIGNAL)on a broken connection must returnEPIPEwithout raising SIGPIPE.sys_sendhonored this only on the AF_UNIX branch; the AF_INET loopback path calledsys_writedirectly, which unconditionally raises SIGPIPE on a closed pipe. A loopback TCP server whose peer closed its read side got a spurious SIGPIPE — terminating a process using the default disposition, the exact outcome MSG_NOSIGNAL exists to prevent.This also contradicted a documented guarantee (
docs/posix-status.md: "MSG_NOSIGNAL is honored for stream/broken-pipe paths"); the fix makes that statement true.Fix
Apply the same save/clear-SIGPIPE handling the AF_UNIX branch already uses to the AF_INET loopback path.
EPIPEis still returned; only the signal is suppressed.ABI
No change.
Validation
cargo test -p kandelo --target aarch64-apple-darwin --lib— 964 pass, including newtest_send_msg_nosignal_inet_loopback(loopback INET connect/accept → close server end →send(MSG_NOSIGNAL)→ assertEPIPE+ no pending SIGPIPE). Verified the test fails without the fix (SIGPIPE raised).scripts/check-abi-version.sh— snapshot in sync.🤖 Generated with Claude Code