Skip to content

fix(libkernel): report EPIPE for a stream send on a connection the peer closed on Windows - #8670

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
xXPBSXx:fix/stream-send-after-reset-epipe
Oct 22, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
xXPBSXx:fix/stream-send-after-reset-epipe

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

What

sosend_generic (uipc_socket.c#L1260-L1264) fails a send on a socket that can send no more with EPIPE before it looks at so_error. Winsock reports the same send as WSAECONNABORTED or WSAECONNRESET, which send, sendto and write passed on as ECONNABORTED or ECONNRESET. SendError now maps both to EPIPE for a stream socket. The send-after-close checks of guest_tcp, guest_socket_read_write and guest_socket_pair, which only ran on Linux, now run on Windows too (the pair test sends until the first failure, because the first send after the peer's close still succeeds on the loopback connection; the Technical debt entry says so).
Fixes #8669
Overlap: git merge-tree has one conflict each with #8483 (both edit the socketpair entry in docs/dev/debt/libkernel.md) and #7850 (open); the other open socket PRs (#8499, #8492, #8474, #8463, #8448, #7090, #7511, #7490) are clean. Whichever lands second rebases. pr_overlap was not run.

Tested

Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on current upstream/main + this commit:

  • guest_socket_read_write and guest_socket_pair fail without the change to Udp.cpp (exit 0xc0000409) and pass with it; guest_tcp passes either way.
  • guest_sce_net, guest_socket_error, guest_udp, guest_poll and guest_recvmsg_memory pass.
  • python tools/check_conventions.py --base upstream/main: 0 errors, 1 warning (debt-length, the edited socketpair entry was already over 1000 characters).
  • Not tested: Linux/macOS (the changed lines are Windows-only; the test edits only widen what runs), a console.

Checklist

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the Windows-specific mapping and regressions. SendError applies the WSAECONNABORTED/WSAECONNRESET to EPIPE translation only for guest stream sockets; the existing datagram and WSAENOTCONN paths are unchanged. The socket, read/write and socket-pair tests now exercise the close/send behavior on Windows, including the documented first-send success on the loopback pair. The author reports a Windows negative control and passing focused socket tests; hosted Windows CI is skipped, so I am relying on that reported platform run rather than claiming independent Windows validation. I found no blocking issue in the diff.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 8344 docs/dev/debt/libkernel.md L189
PR 8658 core/libs/prx/libkernel/Socket/src/Udp.cpp L109

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/libs/prx/libkernel/Socket/src/Udp.cpp
core/libs/tests/GuestSocketPair.cpp
docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestSocketPair.cpp
core/libs/tests/GuestSocketReadWrite.cpp
core/libs/tests/GuestTcp.cpp
PR 6149 docs/dev/debt/libkernel.md
PR 6469 docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6830 docs/dev/debt/libkernel.md
PR 6879 docs/dev/debt/libkernel.md
PR 7088 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 7447 docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md
PR 7565 docs/dev/debt/libkernel.md
PR 7605 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 7653 docs/dev/debt/libkernel.md
PR 8373 docs/dev/debt/libkernel.md
PR 8520 docs/dev/debt/libkernel.md
PR 8553 docs/dev/debt/libkernel.md
PR 9392 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 9509 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 9693 docs/dev/debt/libkernel.md
PR 9770 core/libs/prx/libkernel/Socket/src/Udp.cpp

@cadenasynyster

Copy link
Copy Markdown
Contributor

Independent Windows run of this PR. The review notes that hosted Windows CI is skipped, so this adds a second host.

Environment: Windows 11 10.0.26300, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7 UCRT, Release, BUILD_TESTING=ON. I built only the three affected test targets.

Results:

  • PR head: guest_socket_read_write, guest_tcp and guest_socket_pair all pass.
  • Baseline: I kept the PR's tests and replaced only core/libs/prx/libkernel/Socket/src/Udp.cpp with its base version, then rebuilt. guest_socket_read_write and guest_socket_pair fail with exit 0xc0000409, and guest_tcp passes. This matches the description. I restored the PR's Udp.cpp afterwards.

Not run: other platforms, the other socket tests listed in the description, the full repository CTest, and any title or console run.

AI-assisted: yes

…er closed on Windows

sosend_generic fails a send on a socket that can send no more with EPIPE
before it looks at so_error. Winsock reports the same send as WSAECONNABORTED
or WSAECONNRESET, which reached the guest as ECONNABORTED or ECONNRESET.
A stream send now maps both to EPIPE. The send-after-close checks of
guest_tcp, guest_socket_read_write and guest_socket_pair run on Windows too.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@adriadam10
adriadam10 force-pushed the fix/stream-send-after-reset-epipe branch from 03fd0d9 to ff2b4ba Compare October 22, 2026 17:19
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 22, 2026
@adriadam10
adriadam10 merged commit c55d7c8 into boykopovar:main Oct 22, 2026
10 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Rebased onto main 11f976b: the only conflict was the socketpair entry in docs/dev/debt/libkernel.md, resolved by keeping main's poll text and this PR's send sentence. Checked the SendError mapping (stream sockets only, datagram and WSAENOTCONN unchanged, send/sendto and write callers), the re-enabled close/send tests and the debt entry against the code; Windows runs by @MarcZX10, @cadenasynyster and @xXPBSXx confirm the tests fail without the change. The libkernel tests pass on the rebased head (248 of 248 in scope, local build); merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs fix error Closes an issue (Fixes #N) libkernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libkernel: a stream send on a connection the peer closed fails with ECONNABORTED/ECONNRESET on Windows, FreeBSD 11.4 fails with EPIPE

4 participants