fix(libkernel): stop Winsock failing an unconnected datagram receive after an unreachable port #9477

Merged
EagleBearerYS merged 5 commits from upstream-pr/9477 into main 2026-10-25 17:04:35 +00:00
EagleBearerYS commented 2026-10-21 23:00:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-21T23:00:11Z.


What

Winsock reports an ICMP port-unreachable reply as WSAECONNRESET on the next receive of any datagram socket. So on Windows a guest UDP socket made with socket that sent to a port nobody listens on failed its next recvfrom with ECONNRESET, since libkernel maps WSAECONNRESET to 54.

FreeBSD's udp_common_ctlinput passes the reply on only to a socket connected to the sender, so an unconnected socket keeps receiving. Linux behaves the same way.

socket now turns SIO_UDP_CONNRESET off on datagram sockets on Windows. sceNetSocket in libSceNet keeps Winsock's reporting; #5295 made the same change there and is closed.

The second commit records the trade-off in docs/dev/debt/libkernel.md: on Windows, a datagram socket connected to a port nobody listens on now doesn't fail its next send or receive at all, where FreeBSD fails it with ECONNREFUSED.

socketpair's datagram ends keep Winsock's reporting.

Overlap: #8537 rewrites the setrlimit entry in docs/dev/debt/libkernel.md, right before the socket entry this PR adds. That file is the only one they share. Neither needs to wait for the other: whichever merges second keeps both entries, and this PR takes the rebase in either order (note).

Tested

On GitHub's runners from my fork, merged with main at a6dcea9279 (run):

  • New CheckUnreachablePortIgnored in guest_udp: a non-blocking socket sends to a closed loopback port. Its next three receives must fail with EAGAIN (35), and then a datagram from another socket must arrive.
  • Windows: with main's Udp.cpp the check aborts, because the receive fails with 54. With the change, guest_udp passes 10 runs in a row.
  • Linux: guest_udp passes with main's code and, 10 runs in a row, with the change.
  • On both, every test registered under core/libs/prx/libc and core/libs/prx/libkernel passes: 115 and 197 on Linux, 142 and 207 on Windows.
  • After the merge with main at da54c652e3 (410536f795, no conflicts, the PR's own diff unchanged; run): guest_udp fails on Windows with main's code and passes 10 runs in a row with the change; on Linux it passes both ways. The libc and libkernel suites pass on both (116 and 197 on Linux, 143 and 207 on Windows).
  • After the merge with main at 9a030c2d50 (6b75fb99f6, run): one conflict, in docs/dev/debt/libkernel.md, where #8537 rewrote the setrlimit entry just above this PR's socket entry. The merge keeps main's setrlimit entry and this PR's socket entry after it. The PR's Udp.cpp and GuestUdp.cpp changes are unchanged (same patch-id), and the debt file's added line is the same, with new context. guest_udp fails 3 of 3 on Windows with main's code and passes 10 runs in a row with the change; on Linux it passes both ways. The libc and libkernel suites pass on both (117 and 198 on Linux, 144 and 208 on Windows). They ran with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.
  • tools/check_conventions.py --base origin/main passes.
  • Not tested: macOS, a console, any title.

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 (no order with #8537, see Overlap)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4959497042 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9477). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-21T23:00:11Z. --- ### What Winsock reports an ICMP port-unreachable reply as `WSAECONNRESET` on the next receive of any datagram socket. So on Windows a guest UDP socket made with `socket` that sent to a port nobody listens on failed its next `recvfrom` with `ECONNRESET`, since libkernel maps `WSAECONNRESET` to 54. FreeBSD's [`udp_common_ctlinput`](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/sys/netinet/udp_usrreq.c#L774-L798) passes the reply on only to a socket connected to the sender, so an unconnected socket keeps receiving. Linux behaves the same way. `socket` now turns `SIO_UDP_CONNRESET` off on datagram sockets on Windows. `sceNetSocket` in libSceNet keeps Winsock's reporting; #5295 made the same change there and is closed. The second commit records the trade-off in `docs/dev/debt/libkernel.md`: on Windows, a datagram socket connected to a port nobody listens on now doesn't fail its next send or receive at all, where FreeBSD fails it with `ECONNREFUSED`. `socketpair`'s datagram ends keep Winsock's reporting. **Overlap:** #8537 rewrites the `setrlimit` entry in `docs/dev/debt/libkernel.md`, right before the `socket` entry this PR adds. That file is the only one they share. Neither needs to wait for the other: whichever merges second keeps both entries, and this PR takes the rebase in either order ([note](https://github.com/boykopovar/AnyPS5/pull/8537#issuecomment-6333625221)). ### Tested On GitHub's runners from my fork, merged with `main` at a6dcea9279 ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39685423105)): - New `CheckUnreachablePortIgnored` in `guest_udp`: a non-blocking socket sends to a closed loopback port. Its next three receives must fail with `EAGAIN` (35), and then a datagram from another socket must arrive. - Windows: with `main`'s `Udp.cpp` the check aborts, because the receive fails with 54. With the change, `guest_udp` passes 10 runs in a row. - Linux: `guest_udp` passes with `main`'s code and, 10 runs in a row, with the change. - On both, every test registered under `core/libs/prx/libc` and `core/libs/prx/libkernel` passes: 115 and 197 on Linux, 142 and 207 on Windows. - **After the merge with `main` at da54c652e3** (410536f795, no conflicts, the PR's own diff unchanged; [run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39728737208)): `guest_udp` fails on Windows with `main`'s code and passes 10 runs in a row with the change; on Linux it passes both ways. The libc and libkernel suites pass on both (116 and 197 on Linux, 143 and 207 on Windows). - **After the merge with `main` at 9a030c2d50** (6b75fb99f6, [run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39897509394)): one conflict, in `docs/dev/debt/libkernel.md`, where #8537 rewrote the `setrlimit` entry just above this PR's `socket` entry. The merge keeps `main`'s `setrlimit` entry and this PR's `socket` entry after it. The PR's `Udp.cpp` and `GuestUdp.cpp` changes are unchanged (same patch-id), and the debt file's added line is the same, with new context. `guest_udp` fails 3 of 3 on Windows with `main`'s code and passes 10 runs in a row with the change; on Linux it passes both ways. The libc and libkernel suites pass on both (117 and 198 on Linux, 144 and 208 on Windows). They ran with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. - `tools/check_conventions.py --base origin/main` passes. - Not tested: macOS, a console, any title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 (no order with #8537, see Overlap) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-21 23:04:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T23:04:30Z.

Review: APPROVED


Reviewed the Windows datagram-socket setup, test, and debt note. The SIO_UDP_CONNRESET option is applied only to SOCK_DGRAM sockets created through socket, and the test checks repeated receives after an ICMP unreachable followed by a successful datagram from another sender. The documented connected-socket trade-off is explicit. Conventions, intake, eligibility, labels, and report checks pass; hosted Linux/Windows test/build jobs were skipped. The Windows/Linux focused runs described in the PR are author-reported; I did not run them locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5607301962 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9477#pullrequestreview-5607301962). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T23:04:30Z. **Review:** APPROVED --- Reviewed the Windows datagram-socket setup, test, and debt note. The `SIO_UDP_CONNRESET` option is applied only to `SOCK_DGRAM` sockets created through `socket`, and the test checks repeated receives after an ICMP unreachable followed by a successful datagram from another sender. The documented connected-socket trade-off is explicit. Conventions, intake, eligibility, labels, and report checks pass; hosted Linux/Windows test/build jobs were skipped. The Windows/Linux focused runs described in the PR are author-reported; I did not run them locally.
MarcZX10 commented 2026-10-22 04:30:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:30:50Z.

Review: DISMISSED


The Windows-only SIO_UDP_CONNRESET adjustment is limited to datagram sockets created by socket, and the test verifies the ICMP failure does not poison later receives before a valid datagram arrives. The documented trade-off for connected sockets is explicit. The open overlap #8537 changes the adjacent setrlimit entry in the same docs/dev/debt/libkernel.md; both entries must survive, so please coordinate/record the rebase order under Depends on if a predecessor is required. The branch and test reports are based on a6dcea9279, while current upstream main is ab347d144d. Please rebase and rerun guest_udp, conventions and current overlap checks, preserving the #8537 debt edit. Hosted product jobs are skipped; I did not run local tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609281578 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9477#pullrequestreview-5609281578). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:30:50Z. **Review:** DISMISSED --- The Windows-only `SIO_UDP_CONNRESET` adjustment is limited to datagram sockets created by `socket`, and the test verifies the ICMP failure does not poison later receives before a valid datagram arrives. The documented trade-off for connected sockets is explicit. The open overlap #8537 changes the adjacent `setrlimit` entry in the same `docs/dev/debt/libkernel.md`; both entries must survive, so please coordinate/record the rebase order under `Depends on` if a predecessor is required. The branch and test reports are based on a6dcea9279, while current upstream main is ab347d144d88fae054d9770cf0db8d3565735c02. Please rebase and rerun `guest_udp`, conventions and current overlap checks, preserving the #8537 debt edit. Hosted product jobs are skipped; I did not run local tests.
EagleBearerYS commented 2026-10-22 06:00:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T06:00:30Z.


Thanks, @MarcZX10. The branch now has main at da54c652e3 merged in (410536f795), with the PR's own diff unchanged. On GitHub's runners (run) guest_udp passes 10 runs in a row on both and fails on Windows with main's code; the libc and libkernel suites pass on both, and conventions pass. Tested now says so. #8537's setrlimit entry is kept either way: the order note is on #8537 (comment), and Overlap and Depends on say no order is needed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6333916536 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9477#issuecomment-6333916536). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-22T06:00:30Z. --- Thanks, @MarcZX10. The branch now has `main` at da54c652e3 merged in (410536f795), with the PR's own diff unchanged. On GitHub's runners ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39728737208)) `guest_udp` passes 10 runs in a row on both and fails on Windows with `main`'s code; the libc and libkernel suites pass on both, and conventions pass. Tested now says so. #8537's `setrlimit` entry is kept either way: the order note is on #8537 ([comment](https://github.com/boykopovar/AnyPS5/pull/8537#issuecomment-6333625221)), and Overlap and Depends on say no order is needed.
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!9477
No description provided.