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

Closed
EagleBearerYS wants to merge 2 commits from upstream-pr/9492 into main
EagleBearerYS commented 2026-10-21 23:20:09 +00:00 (Migrated from github.com)

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


Opened again from #5403: title-less conformance fixes of this kind are merged now, for example #7365 and #8411.

What

When the peer of a stream socket closes, Winsock's WSAPoll reports POLLHUP without POLLRDNORM, whether or not the socket's own sending side is shut down. poll passes that on, so on Windows a guest socket whose peer has closed comes back as POLLHUP alone and never 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 does the same, so the Linux path already behaves this way.

On Windows, a stream socket's POLLHUP without POLLERR now reports POLLRDNORM when reading was asked for. It keeps POLLHUP only after shutdown has shut the socket's own sending side, the Socket::sendShut state #4903 added. The two commits:

  • 984e3b517b is the fix and its test;
  • dd117fa25a updates the socketpair note in docs/dev/debt/libkernel.md. Its stream ends are loopback TCP connections, so after the peer's shutdown(SHUT_WR) they now report POLLIN, as the console does. After the peer's close the console also reports POLLHUP, which the loopback connection cannot tell apart from a shutdown.

poll looks the socket up by descriptor, and only when it reports a hang-up without an error. A libSceNet socket waited on through poll (#4933) keeps the flags WSAPoll reports.

Unchanged:

  • A reset or refused connection (POLLHUP with POLLERR) keeps WSAPoll's flags.
  • select already counts a hang-up as readable.

No title is claimed.

Overlap: #8483 makes the same poll change, in poll's collect step, with a new poll debt entry. #5403, where this change was first opened on 2026-10-13, was closed on 10-14 for having no title. Either can go in; the other then closes.

#7605 changes the same poll loop for kqueues, next to the line this PR adds after WSAPoll, and the two compose. Merge order: this PR goes after #7605 (merge order only) and rebases on it.

Tested

On GitHub's runners from my fork, on main at a6dcea9279 (run, of the same tree as these two commits):

guest_poll gains three checks:

  • after a client shuts its own sending side while the server stays open, a POLLIN poll of the client reports nothing;
  • after the client closes and the server reads the end of the stream, the server's socket reports exactly POLLIN | POLLOUT;
  • after the server shuts its sending side too, a POLLIN poll reports POLLIN | POLLHUP.

Results:

  • Windows: with main's Udp.cpp the test aborts. With the change, guest_poll passes 10 runs in a row, and every test registered under core/libs/prx/libc (142) and core/libs/prx/libkernel (207) passes.
  • Linux: guest_poll passes with main's code and, 10 runs in a row, with the change. The libkernel suite (197) passes. In libc (115), the timing test precise_wait failed with and without the change in this run.
  • tools/check_conventions.py --base origin/main passes for both commits.
  • Not tested: macOS, a console, any title.

Checklist

  • Based on current main; #8483 makes the same change (see Overlap)
  • 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: #7605
  • Fixes: #8482
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4959668852 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9492). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-21T23:20:09Z. --- Opened again from #5403: title-less conformance fixes of this kind are merged now, for example #7365 and #8411. ### What When the peer of a stream socket closes, Winsock's `WSAPoll` reports `POLLHUP` without `POLLRDNORM`, whether or not the socket's own sending side is shut down. `poll` passes that on, so on Windows a guest socket whose peer has closed comes back as `POLLHUP` alone and never as `POLLIN`. FreeBSD's [`sopoll_generic`](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/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` does the same, so the Linux path already behaves this way. On Windows, a stream socket's `POLLHUP` without `POLLERR` now reports `POLLRDNORM` when reading was asked for. It keeps `POLLHUP` only after `shutdown` has shut the socket's own sending side, the `Socket::sendShut` state #4903 added. The two commits: - 984e3b517b is the fix and its test; - dd117fa25a updates the `socketpair` note in `docs/dev/debt/libkernel.md`. Its stream ends are loopback TCP connections, so after the peer's `shutdown(SHUT_WR)` they now report `POLLIN`, as the console does. After the peer's `close` the console also reports `POLLHUP`, which the loopback connection cannot tell apart from a shutdown. `poll` looks the socket up by descriptor, and only when it reports a hang-up without an error. A libSceNet socket waited on through `poll` (#4933) keeps the flags `WSAPoll` reports. Unchanged: - A reset or refused connection (`POLLHUP` with `POLLERR`) keeps `WSAPoll`'s flags. - `select` already counts a hang-up as readable. No title is claimed. **Overlap:** #8483 makes the same `poll` change, in `poll`'s `collect` step, with a new `poll` debt entry. #5403, where this change was first opened on 2026-10-13, was closed on 10-14 for having no title. Either can go in; the other then closes. #7605 changes the same `poll` loop for kqueues, next to the line this PR adds after `WSAPoll`, and the two compose. Merge order: this PR goes after #7605 (merge order only) and rebases on it. ### Tested On GitHub's runners from my fork, on `main` at a6dcea9279 ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39688860921), of the same tree as these two commits): `guest_poll` gains three checks: - after a client shuts its own sending side while the server stays open, a `POLLIN` poll of the client reports nothing; - after the client closes and the server reads the end of the stream, the server's socket reports exactly `POLLIN | POLLOUT`; - after the server shuts its sending side too, a `POLLIN` poll reports `POLLIN | POLLHUP`. Results: - Windows: with `main`'s `Udp.cpp` the test aborts. With the change, `guest_poll` passes 10 runs in a row, and every test registered under `core/libs/prx/libc` (142) and `core/libs/prx/libkernel` (207) passes. - Linux: `guest_poll` passes with `main`'s code and, 10 runs in a row, with the change. The libkernel suite (197) passes. In libc (115), the timing test `precise_wait` failed with and without the change in this run. - `tools/check_conventions.py --base origin/main` passes for both commits. - 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`; #8483 makes the same change (see Overlap) - [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: #7605 - [x] Fixes: #8482 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-21 23:27:47 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


This PR implements the same Windows poll behavior as the still-open #8483, and the two PRs change the same Udp.cpp poll path. The body already identifies #8483 and says only one should go in. Please resolve that overlap with the other contributor and maintainers, then update or close one PR before this duplicate work proceeds. I have not assessed which implementation should be selected; both should not be merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5607469699 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9492#pullrequestreview-5607469699). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T23:27:47Z. **Review:** CHANGES_REQUESTED --- This PR implements the same Windows `poll` behavior as the still-open #8483, and the two PRs change the same `Udp.cpp` poll path. The body already identifies #8483 and says only one should go in. Please resolve that overlap with the other contributor and maintainers, then update or close one PR before this duplicate work proceeds. I have not assessed which implementation should be selected; both should not be merged.
EagleBearerYS commented 2026-10-22 00:41:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T00:41:12Z.


Thanks, @MarcZX10. I've raised it on #8483 (comment) and will settle with its author and the maintainers which of the two stays; the other then closes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329838421 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9492#issuecomment-6329838421). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-22T00:41:12Z. --- Thanks, @MarcZX10. I've raised it on #8483 ([comment](https://github.com/boykopovar/AnyPS5/pull/8483#issuecomment-6328783552)) and will settle with its author and the maintainers which of the two stays; the other then closes.
MarcZX10 commented 2026-10-22 02:11:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T02:11:56Z.


Thanks for raising the duplicate with #8483. I still do not see an agreement from that PR author or maintainers on which implementation will proceed, so the duplicate remains unresolved. Also, #7605 edits the same poll loop and the PR body describes the changes as composing; please list the required merge order under Depends on and preserve that rebase sequence. Once the duplicate choice is settled, update or close the superseded PR, update the checklist, and rebase the surviving branch on current main before requesting another review. I have not rerun tests locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6331015700 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9492#issuecomment-6331015700). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T02:11:56Z. --- Thanks for raising the duplicate with #8483. I still do not see an agreement from that PR author or maintainers on which implementation will proceed, so the duplicate remains unresolved. Also, #7605 edits the same `poll` loop and the PR body describes the changes as composing; please list the required merge order under `Depends on` and preserve that rebase sequence. Once the duplicate choice is settled, update or close the superseded PR, update the checklist, and rebase the surviving branch on current `main` before requesting another review. I have not rerun tests locally.
EagleBearerYS commented 2026-10-22 02:19:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T02:19:02Z.


Thanks, @MarcZX10. Depends on now lists #7605, and the Overlap section says this PR goes after it and rebases on it. On #8483, the question of which one stays is with its author and the maintainers. Once it's settled, the other closes, and the surviving branch gets its checklist updated and is brought up to date with current main before another review.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6331104351 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9492#issuecomment-6331104351). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-22T02:19:02Z. --- Thanks, @MarcZX10. Depends on now lists #7605, and the Overlap section says this PR goes after it and rebases on it. On #8483, the question of which one stays is with its author and the maintainers. Once it's settled, the other closes, and the surviving branch gets its checklist updated and is brought up to date with current `main` before another review.
MarcZX10 commented 2026-10-22 04:27:16 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


The Windows poll translation is scoped to stream POLLHUP without POLLERR, and its regression checks half-close, peer close/EOF, and the both-directions-shut state. The PR correctly records #7605 as a prerequisite and includes Fixes: #8482; #8482 remains open. However, duplicate work #8483 is also still open and implements the same behavior. The PR itself says one should close, but there is still no author/maintainer decision. Please resolve that choice with #8483’s author and maintainers, update/close the superseded PR, and preserve the #7605 order. This branch and its tests are based on a6dcea9279, while current upstream main is ab347d144d; rebase the surviving PR and rerun guest_poll, conventions and overlap checks on current main. Also preserve the #8344/#8483/#8670 debt edits and manually compare #5021’s Udp.cpp warning. Hosted product jobs are skipped; I did not run local tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609260226 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9492#pullrequestreview-5609260226). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:27:16Z. **Review:** CHANGES_REQUESTED --- The Windows `poll` translation is scoped to stream `POLLHUP` without `POLLERR`, and its regression checks half-close, peer close/EOF, and the both-directions-shut state. The PR correctly records #7605 as a prerequisite and includes `Fixes: #8482`; #8482 remains open. However, duplicate work #8483 is also still open and implements the same behavior. The PR itself says one should close, but there is still no author/maintainer decision. Please resolve that choice with #8483’s author and maintainers, update/close the superseded PR, and preserve the #7605 order. This branch and its tests are based on a6dcea9279, while current upstream main is ab347d144d88fae054d9770cf0db8d3565735c02; rebase the surviving PR and rerun `guest_poll`, conventions and overlap checks on current main. Also preserve the #8344/#8483/#8670 debt edits and manually compare #5021’s Udp.cpp warning. Hosted product jobs are skipped; I did not run local tests.

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!9492
No description provided.