fix(libkernel): report a stream whose peer closed as readable in poll on Windows #8483

Merged
xXPBSXx merged 2 commits from upstream-pr/8483 into main 2026-10-22 15:44:28 +00:00
xXPBSXx commented 2026-10-20 13:27:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T13:27:47Z.


What

WSAPoll reports POLLHUP alone for a stream socket whose peer has closed, whether or not the socket's own sending side is shut. poll passed that on, so on Windows such a socket never came back as POLLIN. FreeBSD's sopoll_generic reports a socket that can receive no more as readable and adds POLLHUP only once it can send no more either (Linux's poll already does this). On Windows, a guest stream socket's POLLHUP without POLLERR now also reports the read bit that was asked for, and keeps POLLHUP only after shutdown has shut the socket's own sending side (Socket::sendShut). A reset or refused connection (POLLHUP with POLLERR) and libSceNet sockets keep WSAPoll's flags. A new Technical debt entry says so.
Fixes #8482
Overlap: git merge-tree against the open socket PRs #7090, #8392, #8448, #8463, #8474, #7511, #7850, #7490 and #8312 is clean. pr_overlap was not run.

Tested

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

  • guest_poll: the new case aborts without the change to Udp.cpp and passes with it. It checks POLLIN, POLLIN|POLLOUT, POLLRDNORM and POLLOUT alone after the peer's shutdown(SHUT_WR) (no POLLHUP), recv returning 0, and POLLIN|POLLHUP on both ends once the other side has shut its sending side too.
  • guest_sce_net, guest_socket_error, guest_udp, guest_select, guest_select_wait, guest_tcp, guest_socket_pair and guest_recvmsg_memory pass.
  • python tools/check_conventions.py --base upstream/main: passes.
  • Other tests that call poll (guest_socket_descriptors, guest_socket_options) were not rerun by me for this change; their poll calls do not involve a peer that closed.
  • Not tested: Linux/macOS, a console, a title run, a reset connection, a close by the peer with unread data.

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; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: #8482
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4936457242 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8483). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T13:27:47Z. --- ### What `WSAPoll` reports `POLLHUP` alone for a stream socket whose peer has closed, whether or not the socket's own sending side is shut. `poll` passed that on, so on Windows such a socket never came back as `POLLIN`. FreeBSD's [`sopoll_generic`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_socket.c#L3080-L3086) reports a socket that can receive no more as readable and adds `POLLHUP` only once it can send no more either (Linux's `poll` already does this). On Windows, a guest stream socket's `POLLHUP` without `POLLERR` now also reports the read bit that was asked for, and keeps `POLLHUP` only after `shutdown` has shut the socket's own sending side (`Socket::sendShut`). A reset or refused connection (`POLLHUP` with `POLLERR`) and libSceNet sockets keep `WSAPoll`'s flags. A new Technical debt entry says so. Fixes #8482 Overlap: `git merge-tree` against the open socket PRs #7090, #8392, #8448, #8463, #8474, #7511, #7850, #7490 and #8312 is clean. `pr_overlap` was not run. ### Tested Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on upstream/main 3cde166e45 + this commit: - `guest_poll`: the new case aborts without the change to `Udp.cpp` and passes with it. It checks `POLLIN`, `POLLIN|POLLOUT`, `POLLRDNORM` and `POLLOUT` alone after the peer's `shutdown(SHUT_WR)` (no `POLLHUP`), `recv` returning 0, and `POLLIN|POLLHUP` on both ends once the other side has shut its sending side too. - `guest_sce_net`, `guest_socket_error`, `guest_udp`, `guest_select`, `guest_select_wait`, `guest_tcp`, `guest_socket_pair` and `guest_recvmsg_memory` pass. - `python tools/check_conventions.py --base upstream/main`: passes. - Other tests that call `poll` (`guest_socket_descriptors`, `guest_socket_options`) were not rerun by me for this change; their `poll` calls do not involve a peer that closed. - Not tested: Linux/macOS, a console, a title run, a reset connection, a `close` by the peer with unread data. ### 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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: #8482 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-20 13:47:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T13:47:08Z.


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 7605 docs/dev/debt/libkernel.md L201
PR 8344 docs/dev/debt/libkernel.md L189
PR 9492 core/libs/prx/libkernel/Socket/src/Udp.cpp L540
docs/dev/debt/libkernel.md L189
PR 9512 core/libs/tests/GuestPoll.cpp L214, L216
docs/dev/debt/libkernel.md L201

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
docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestPoll.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
core/libs/tests/GuestPoll.cpp
PR 7447 docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md
PR 7565 docs/dev/debt/libkernel.md
PR 7653 docs/dev/debt/libkernel.md
PR 8520 docs/dev/debt/libkernel.md
PR 8553 docs/dev/debt/libkernel.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6292367372 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8483#issuecomment-6292367372). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T13:47:08Z. --- <!-- 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 | |---|---|---|---| | [PR 7605](https://www.github.com/boykopovar/AnyPS5/pull/7605) | `docs/dev/debt/libkernel.md` [L201](https://github.com/boykopovar/AnyPS5/blob/329efe1bfdaff116c57cdf62718026ee4f5521ae/docs/dev/debt/libkernel.md#L201) | | | | [PR 8344](https://www.github.com/boykopovar/AnyPS5/pull/8344) | `docs/dev/debt/libkernel.md` [L189](https://github.com/boykopovar/AnyPS5/blob/329efe1bfdaff116c57cdf62718026ee4f5521ae/docs/dev/debt/libkernel.md#L189) | | | | [PR 9492](https://www.github.com/boykopovar/AnyPS5/pull/9492) | `core/libs/prx/libkernel/Socket/src/Udp.cpp` [L540](https://github.com/boykopovar/AnyPS5/blob/329efe1bfdaff116c57cdf62718026ee4f5521ae/core/libs/prx/libkernel/Socket/src/Udp.cpp#L540)<br>`docs/dev/debt/libkernel.md` [L189](https://github.com/boykopovar/AnyPS5/blob/329efe1bfdaff116c57cdf62718026ee4f5521ae/docs/dev/debt/libkernel.md#L189) | | | | [PR 9512](https://www.github.com/boykopovar/AnyPS5/pull/9512) | `core/libs/tests/GuestPoll.cpp` [L214](https://github.com/boykopovar/AnyPS5/blob/329efe1bfdaff116c57cdf62718026ee4f5521ae/core/libs/tests/GuestPoll.cpp#L214), [L216](https://github.com/boykopovar/AnyPS5/blob/329efe1bfdaff116c57cdf62718026ee4f5521ae/core/libs/tests/GuestPoll.cpp#L216)<br>`docs/dev/debt/libkernel.md` [L201](https://github.com/boykopovar/AnyPS5/blob/329efe1bfdaff116c57cdf62718026ee4f5521ae/docs/dev/debt/libkernel.md#L201) | | | 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](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestPoll.cpp` | | [PR 6149](https://www.github.com/boykopovar/AnyPS5/pull/6149) | `docs/dev/debt/libkernel.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `docs/dev/debt/libkernel.md` | | [PR 6740](https://www.github.com/boykopovar/AnyPS5/pull/6740) | `docs/dev/debt/libkernel.md` | | [PR 6830](https://www.github.com/boykopovar/AnyPS5/pull/6830) | `docs/dev/debt/libkernel.md` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `docs/dev/debt/libkernel.md` | | [PR 7088](https://www.github.com/boykopovar/AnyPS5/pull/7088) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7105](https://www.github.com/boykopovar/AnyPS5/pull/7105) | `docs/dev/debt/libkernel.md` | | [PR 7149](https://www.github.com/boykopovar/AnyPS5/pull/7149) | `docs/dev/debt/libkernel.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`core/libs/tests/GuestPoll.cpp` | | [PR 7447](https://www.github.com/boykopovar/AnyPS5/pull/7447) | `docs/dev/debt/libkernel.md` | | [PR 7509](https://www.github.com/boykopovar/AnyPS5/pull/7509) | `docs/dev/debt/libkernel.md` | | [PR 7565](https://www.github.com/boykopovar/AnyPS5/pull/7565) | `docs/dev/debt/libkernel.md` | | [PR 7653](https://www.github.com/boykopovar/AnyPS5/pull/7653) | `docs/dev/debt/libkernel.md` | | [PR 8520](https://www.github.com/boykopovar/AnyPS5/pull/8520) | `docs/dev/debt/libkernel.md` | | [PR 8553](https://www.github.com/boykopovar/AnyPS5/pull/8553) | `docs/dev/debt/libkernel.md` |
oneandonlydean commented 2026-10-20 14:26:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T14:26:20Z.


Thanks, this matches sopoll_generic for a TCP peer that closed. One follow-up in docs/dev/debt/libkernel.md: the socketpair entry still says "On Windows poll on a stream end reports POLLHUP without POLLIN after the peer's shutdown(SHUT_WR) or close". With this change that's no longer true, since a socketpair stream end is a loopback TCP connection on Windows. The remaining gap is narrower. After the peer's close, FreeBSD's unp_drop disconnects the other end, so the console reports POLLIN | POLLHUP, while Windows now reports POLLIN alone (the end hasn't shut its own sending side). Could you update that sentence to describe what's left?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6293184267 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8483#issuecomment-6293184267). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T14:26:20Z. --- Thanks, this matches `sopoll_generic` for a TCP peer that closed. One follow-up in `docs/dev/debt/libkernel.md`: the `socketpair` entry still says "On Windows `poll` on a stream end reports `POLLHUP` without `POLLIN` after the peer's `shutdown(SHUT_WR)` or `close`". With this change that's no longer true, since a socketpair stream end is a loopback TCP connection on Windows. The remaining gap is narrower. After the peer's `close`, FreeBSD's `unp_drop` disconnects the other end, so the console reports `POLLIN | POLLHUP`, while Windows now reports `POLLIN` alone (the end hasn't shut its own sending side). Could you update that sentence to describe what's left?
xXPBSXx commented 2026-10-20 14:59:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T14:59:46Z.


Fixed in ab21d78896: the socketpair entry in docs/dev/debt/libkernel.md now says that a pair end reports POLLIN after the peer's shutdown(SHUT_WR) or close on Windows; the remaining gap is that after close the console also reports POLLHUP (unp_drop disconnects the other end), which the loopback connection cannot tell from a shutdown, so no POLLHUP is reported. Docs only; no code change.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6293915983 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8483#issuecomment-6293915983). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T14:59:46Z. --- Fixed in ab21d78896: the socketpair entry in docs/dev/debt/libkernel.md now says that a pair end reports POLLIN after the peer's shutdown(SHUT_WR) or close on Windows; the remaining gap is that after close the console also reports POLLHUP (unp_drop disconnects the other end), which the loopback connection cannot tell from a shutdown, so no POLLHUP is reported. Docs only; no code change. AI-assisted (Claude Code).
Filip722 commented 2026-10-21 09:27:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Filip722 on 2026-10-21T09:27:14Z.


Linux follow-up validation of exact PR head ab21d78896d2db26706fe03c195466f0ca78540f: all 11 selected poll/socket tests passed three consecutive executions each (33 successful executions, no failures or skips).

Environment: Debian 13.7 x86-64, Linux 7.2.9-x64v3-xanmod1, AMD Ryzen 5 7640HS, GCC 15.2.0, CMake 3.31.6, Release, BUILD_TESTING=ON, ANYPS5_RELINKER_ONLY=OFF, bundled dependencies. Configured the full project in an isolated checkout and built libkernel, the selected test executables, and their dependencies with two jobs. Tracked source files remained unchanged.

  • guest_poll passed the new PollsAStreamWhosePeerClosed regression: after the peer's shutdown(SHUT_WR), exact results were POLLIN, POLLIN|POLLOUT, POLLRDNORM, or POLLOUT according to the requested mask, with no POLLHUP; recv returned 0; after both sending sides were shut, both ends reported POLLIN|POLLHUP. The complete test took about 0.30 s per execution.
  • The additional guest_socket_descriptors and guest_socket_options tests, listed as not rerun in the PR description, also passed all three executions on Linux.
  • The remaining controls passed: guest_sce_net, guest_socket_error, guest_udp, guest_select, guest_select_wait, guest_tcp, guest_socket_pair, and guest_recvmsg_memory.

Command:

ctest --test-dir build \
  -R '^(guest_poll|guest_sce_net|guest_socket_error|guest_udp|guest_select|guest_select_wait|guest_tcp|guest_socket_pair|guest_recvmsg_memory|guest_socket_descriptors|guest_socket_options)$' \
  --repeat until-fail:3 -V

The production fix is Windows-only, so this adds Linux coverage for the shared regression and surrounding socket behavior. No new Windows run, macOS, PS5 hardware, title, GPU, or full repository test-suite validation was performed.

AI-assisted testing and report.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6312634732 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8483#issuecomment-6312634732). Originally posted by [Filip722](https://github.com/Filip722) on 2026-10-21T09:27:14Z. --- Linux follow-up validation of exact PR head `ab21d78896d2db26706fe03c195466f0ca78540f`: all 11 selected poll/socket tests passed three consecutive executions each (33 successful executions, no failures or skips). Environment: Debian 13.7 x86-64, Linux `7.2.9-x64v3-xanmod1`, AMD Ryzen 5 7640HS, GCC 15.2.0, CMake 3.31.6, Release, `BUILD_TESTING=ON`, `ANYPS5_RELINKER_ONLY=OFF`, bundled dependencies. Configured the full project in an isolated checkout and built `libkernel`, the selected test executables, and their dependencies with two jobs. Tracked source files remained unchanged. - `guest_poll` passed the new `PollsAStreamWhosePeerClosed` regression: after the peer's `shutdown(SHUT_WR)`, exact results were `POLLIN`, `POLLIN|POLLOUT`, `POLLRDNORM`, or `POLLOUT` according to the requested mask, with no `POLLHUP`; `recv` returned 0; after both sending sides were shut, both ends reported `POLLIN|POLLHUP`. The complete test took about 0.30 s per execution. - The additional `guest_socket_descriptors` and `guest_socket_options` tests, listed as not rerun in the PR description, also passed all three executions on Linux. - The remaining controls passed: `guest_sce_net`, `guest_socket_error`, `guest_udp`, `guest_select`, `guest_select_wait`, `guest_tcp`, `guest_socket_pair`, and `guest_recvmsg_memory`. Command: ```sh ctest --test-dir build \ -R '^(guest_poll|guest_sce_net|guest_socket_error|guest_udp|guest_select|guest_select_wait|guest_tcp|guest_socket_pair|guest_recvmsg_memory|guest_socket_descriptors|guest_socket_options)$' \ --repeat until-fail:3 -V ``` The production fix is Windows-only, so this adds Linux coverage for the shared regression and surrounding socket behavior. No new Windows run, macOS, PS5 hardware, title, GPU, or full repository test-suite validation was performed. AI-assisted testing and report.
EagleBearerYS commented 2026-10-21 23:23:05 +00:00 (Migrated from github.com)

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


@xXPBSXx a heads-up: #9492 makes the same change to poll. It's #5403, first opened on 2026-10-13 and closed on 10-14 for having no title, now open again. Either can go in; the other then closes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6328783552 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8483#issuecomment-6328783552). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-21T23:23:05Z. --- @xXPBSXx a heads-up: #9492 makes the same change to `poll`. It's #5403, first opened on 2026-10-13 and closed on 10-14 for having no title, now open again. Either can go in; the other then closes.
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!8483
No description provided.