Skip to content

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

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
xXPBSXx:fix/poll-peer-close-pollin
Oct 22, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
xXPBSXx:fix/poll-peer-close-pollin

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

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 3cde166 + 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: libkernel: poll on Windows reports a stream whose peer closed as POLLHUP only, never as POLLIN #8482
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@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 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

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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
xXPBSXx force-pushed the fix/poll-peer-close-pollin branch from 66e92b2 to ab21d78 Compare October 20, 2026 14:58
@xXPBSXx

xXPBSXx commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in ab21d78: 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

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 21, 2026
… on Windows

WSAPoll reports POLLHUP alone for a stream socket whose peer has closed, so
poll never returned POLLIN for it and a caller waiting for POLLIN did not see
the end of the stream. sopoll_generic reports a socket that can receive no
more as readable and adds POLLHUP only once it can send no more either.
poll now adds the requested read bit and keeps POLLHUP only after the socket
shut its own sending side. A reset or refused connection keeps WSAPoll's flags.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…eer closes

On Windows a pair end now reports POLLIN after the peer's shutdown or close.
The console also reports POLLHUP after close; the loopback connection cannot
tell a close from a shutdown.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@xXPBSXx
xXPBSXx force-pushed the fix/poll-peer-close-pollin branch from ab21d78 to 9abca4b Compare October 21, 2026 13:01
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 21, 2026
@adriadam10 adriadam10 self-assigned this Oct 21, 2026
@EagleBearerYS

Copy link
Copy Markdown
Contributor

@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.

@adriadam10
adriadam10 merged commit 093149c into boykopovar:main Oct 22, 2026
10 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Re-checked against current main (eaff876): main's #8492 change in Udp.cpp is in recv/recvfrom and does not touch the poll hunk, which applies without conflict. ClosedStreamEvents only takes socket->modeMutex, which poll does not hold while it collects results. Logic matches sopoll_generic; Windows runs in the merge queue's Build. #9492 makes the same change: whichever merges first, the other closes. merged.

iamthehimansh added a commit to iamthehimansh/AnyPS5 that referenced this pull request Oct 22, 2026
…table in poll on macOS

boykopovar#8483 corrects Windows poll for a stream socket whose peer shut its
write side: readable, POLLRDNORM when asked, and no POLLHUP while this
side can still send. XNU reports the same POLLHUP and, when POLLIN and
POLLOUT are both requested, also drops POLLOUT, so guest_poll's new
PollsAStreamWhosePeerClosed failed on macOS.

On macOS the same ClosedStreamEvents correction now runs, and while this
side has not shut its write side it re-checks POLLOUT with a zero-timeout
poll and adds it back. Linux and Windows unchanged.
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: poll on Windows reports a stream whose peer closed as POLLHUP only, never as POLLIN

5 participants