fix(libkernel): report EPIPE for a stream send after the peer closed on Windows #5510

Closed
simonbronk wants to merge 1 commit from upstream-pr/5510 into main
simonbronk commented 2026-10-13 21:49:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-13T21:49:56Z.


What

On Windows, a send or write on a stream socket whose peer has closed fails with ECONNABORTED (53) or ECONNRESET (54), because Winsock reports WSAECONNABORTED/WSAECONNRESET and NativeError maps them by name. FreeBSD 11.4 reports EPIPE (32): sosend_generic checks SBS_CANTSENDMORE before so_error, and the peer's reset sets it through soisdisconnected. A guest that checks for EPIPE to notice a dropped connection did not see it on Windows.

SendError (used by send, sendto and so by write/_write on a guest socket) now returns EPIPE for those two errors on a stream socket on Windows, as it already does for WSAESHUTDOWN. Datagram sockets and Linux are unchanged.

The two checks that were Linux-only for this reason now run on Windows too: the write loop after the peer's close in guest_socket_read_write, and the send loop in guest_tcp. The libkernel.md debt entries are updated: "Socket error numbers" records the mapping, and "socketpair" no longer says a stream send after the peer closed reports ECONNABORTED; on Windows the first such send still succeeds (the pair is a loopback TCP connection), and the next one now reports EPIPE.

sendfile's SendAll still uses NativeError; it is not covered by a test here, so it is left for a follow-up.

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, full build, on main 665ad7da7:

  • With main's Udp.cpp and the checks enabled: guest_socket_read_write fails at the write loop (errno 53 on the second write). guest_tcp passes either way, since its send loop follows a local shutdown(SHUT_WR) (WSAESHUTDOWN).
  • With the change: guest_tcp, guest_socket_read_write, guest_socket_pair, guest_sce_net, guest_poll and guest_udp pass 20/20 (--repeat until-fail:20); full ctest 1099/1099.
  • Probe on a socketpair stream end after the peer's close (not committed): first send succeeds, second fails with EPIPE (3/3 runs); before the change the second failed with ECONNABORTED.
  • Linux: not run; the change is inside #ifdef _WIN32.
  • tools/check_conventions.py --base upstream/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4849928269 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5510). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-13T21:49:56Z. --- ### What On Windows, a `send` or `write` on a stream socket whose peer has closed fails with `ECONNABORTED` (53) or `ECONNRESET` (54), because Winsock reports `WSAECONNABORTED`/`WSAECONNRESET` and `NativeError` maps them by name. FreeBSD 11.4 reports `EPIPE` (32): [`sosend_generic`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/sys/kern/uipc_socket.c#L1260-L1270) checks `SBS_CANTSENDMORE` before `so_error`, and the peer's reset sets it through [`soisdisconnected`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/sys/kern/uipc_socket.c#L3512-L3534). A guest that checks for `EPIPE` to notice a dropped connection did not see it on Windows. `SendError` (used by `send`, `sendto` and so by `write`/`_write` on a guest socket) now returns `EPIPE` for those two errors on a stream socket on Windows, as it already does for `WSAESHUTDOWN`. Datagram sockets and Linux are unchanged. The two checks that were Linux-only for this reason now run on Windows too: the `write` loop after the peer's `close` in `guest_socket_read_write`, and the `send` loop in `guest_tcp`. The `libkernel.md` debt entries are updated: "Socket error numbers" records the mapping, and "socketpair" no longer says a stream `send` after the peer closed reports `ECONNABORTED`; on Windows the first such send still succeeds (the pair is a loopback TCP connection), and the next one now reports `EPIPE`. `sendfile`'s `SendAll` still uses `NativeError`; it is not covered by a test here, so it is left for a follow-up. ### Tested Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, full build, on `main` `665ad7da7`: - With `main`'s `Udp.cpp` and the checks enabled: `guest_socket_read_write` fails at the `write` loop (`errno 53` on the second write). `guest_tcp` passes either way, since its `send` loop follows a local `shutdown(SHUT_WR)` (`WSAESHUTDOWN`). - With the change: `guest_tcp`, `guest_socket_read_write`, `guest_socket_pair`, `guest_sce_net`, `guest_poll` and `guest_udp` pass 20/20 (`--repeat until-fail:20`); full `ctest` 1099/1099. - Probe on a `socketpair` stream end after the peer's `close` (not committed): first `send` succeeds, second fails with `EPIPE` (3/3 runs); before the change the second failed with `ECONNABORTED`. - Linux: not run; the change is inside `#ifdef _WIN32`. - `tools/check_conventions.py --base upstream/main` passes. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
github-actions[bot] commented 2026-10-13 22:15:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T22:15:06Z.


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
#4796 docs/dev/debt/libkernel.md L154
#4933 docs/dev/debt/libkernel.md L153-154
#4993 docs/dev/debt/libkernel.md L153-154
#5403 docs/dev/debt/libkernel.md L148
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6156343042 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5510#issuecomment-6156343042). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T22:15:06Z. --- <!-- pr-overlap --> 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 | |---|---|---|---| | #4796 | `docs/dev/debt/libkernel.md` [L154](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/docs/dev/debt/libkernel.md#L154) | | | | #4933 | `docs/dev/debt/libkernel.md` [L153-154](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/docs/dev/debt/libkernel.md#L153-L154) | | | | #4993 | `docs/dev/debt/libkernel.md` [L153-154](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/docs/dev/debt/libkernel.md#L153-L154) | | | | #5403 | `docs/dev/debt/libkernel.md` [L148](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/docs/dev/debt/libkernel.md#L148) | | |
oneandonlydean commented 2026-10-14 02:25:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:25:44Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159505247 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5510#issuecomment-6159505247). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:25:44Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!5510
No description provided.