fix(libkernel): clear POLLOUT from a hung-up socket in poll on Linux #9512

Merged
EagleBearerYS merged 2 commits from upstream-pr/9512 into main 2026-10-25 20:16:45 +00:00
EagleBearerYS commented 2026-10-21 23:56:24 +00:00 (Migrated from github.com)

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


Title-less conformance fixes of this kind are merged now, for example #7365 and #8411.

What

FreeBSD 11.4's pollscan clears POLLOUT whenever a descriptor reports POLLHUP (sys_generic.c L1593-L1598: "POSIX requires POLLOUT to be never set simultaneously with POLLHUP"). libkernel's poll does that for pipes, but on Linux a stream socket whose peer has closed and whose own sending side is shut down reports POLLOUT next to POLLHUP, because Linux's poll sets both.

Linux sets POLLHUP on a socket only once both directions are shut, the same condition as FreeBSD's sopoll_generic, so poll now clears POLLOUT from any entry that reports POLLHUP on Linux. Windows keeps the flags WSAPoll reports; #9492 changes how they are read on Windows.

The second commit adds a poll on a stream socket entry to docs/dev/debt/libkernel.md.

No title is claimed.

Overlap, merge order only: this PR goes after #7605, which rewrites the poll entry of docs/dev/debt/libkernel.md that this PR's new entry follows; the code changes merge cleanly. #8483 has landed (093149c5bd), and this PR is merged with it (3373495360): #8483's Windows change and this PR's Linux one sit side by side in poll, and guest_poll runs both tests.

Tested

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

  • New PollsAHungUpSocketWithoutPollout in guest_poll, on Linux: the client closes, the server reads the end of the stream and shuts its own sending side, and a POLLIN | POLLOUT poll of the server must report exactly POLLIN | POLLHUP.
  • Linux: with main's Udp.cpp guest_poll fails. With the change it passes 10 runs in a row.
  • Windows: the check isn't built there, and guest_poll passes with and without 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 ab347d144d (1983ed955d, run): on Linux guest_poll fails with main's Udp.cpp and passes 10 runs in a row with the change; on Windows it passes both ways. The libc and libkernel suites pass on both (116 and 197 on Linux, 143 and 207 on Windows). tools/pr_overlap.py and git merge-tree find the same overlaps as before: #7605 in the debt file, #8483 in GuestPoll.cpp and the debt file, and none with #9492.
  • 3373495360, main 8499ea52e5 merged in, which includes #8483 (run). Both sides of GuestPoll.cpp are kept: #8483's PollsAStreamWhosePeerClosed and this PR's PollsAHungUpSocketWithoutPollout, each called from main(), and both debt entries. The PR's diff otherwise loses only the shutdown_nid_postfix declaration, which main now has. On Linux guest_poll fails 3 of 3 with main's Udp.cpp and passes 10 of 10 with the change; on Windows it passes both ways. The libc and libkernel suites pass on both runners. The libc and libkernel suites 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.
  • xXPBSXx's run (comment): WSL2 Ubuntu 24.04 (a virtualised kernel), GCC 13.3.0, Release, the PR head alone on its merge base a6dcea9279. guest_poll passes 3 of 3, and with Udp.cpp at the merge base and the PR's tests kept, it aborts.
  • 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: #7605
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4959952691 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9512). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-21T23:56:24Z. --- Title-less conformance fixes of this kind are merged now, for example #7365 and #8411. ### What FreeBSD 11.4's `pollscan` clears `POLLOUT` whenever a descriptor reports `POLLHUP` ([`sys_generic.c` L1593-L1598](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/sys_generic.c#L1593-L1598): "POSIX requires POLLOUT to be never set simultaneously with POLLHUP"). libkernel's `poll` does that for pipes, but on Linux a stream socket whose peer has closed and whose own sending side is shut down reports `POLLOUT` next to `POLLHUP`, because Linux's `poll` sets both. Linux sets `POLLHUP` on a socket only once both directions are shut, the same condition as FreeBSD's `sopoll_generic`, so `poll` now clears `POLLOUT` from any entry that reports `POLLHUP` on Linux. Windows keeps the flags `WSAPoll` reports; #9492 changes how they are read on Windows. The second commit adds a `poll on a stream socket` entry to `docs/dev/debt/libkernel.md`. No title is claimed. **Overlap, merge order only:** this PR goes after #7605, which rewrites the `poll` entry of `docs/dev/debt/libkernel.md` that this PR's new entry follows; the code changes merge cleanly. #8483 has landed (093149c5bd), and this PR is merged with it (3373495360): #8483's Windows change and this PR's Linux one sit side by side in `poll`, and `guest_poll` runs both tests. ### Tested On GitHub's runners from my fork, on `main` at a6dcea9279 ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39694538695)): - New `PollsAHungUpSocketWithoutPollout` in `guest_poll`, on Linux: the client closes, the server reads the end of the stream and shuts its own sending side, and a `POLLIN | POLLOUT` poll of the server must report exactly `POLLIN | POLLHUP`. - Linux: with `main`'s `Udp.cpp` `guest_poll` fails. With the change it passes 10 runs in a row. - Windows: the check isn't built there, and `guest_poll` passes with and without 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 ab347d144d (1983ed955d, [run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39723082925)): on Linux `guest_poll` fails with `main`'s `Udp.cpp` and passes 10 runs in a row with the change; on Windows it passes both ways. The libc and libkernel suites pass on both (116 and 197 on Linux, 143 and 207 on Windows). `tools/pr_overlap.py` and `git merge-tree` find the same overlaps as before: #7605 in the debt file, #8483 in `GuestPoll.cpp` and the debt file, and none with #9492. - **3373495360, `main` 8499ea52e5 merged in**, which includes #8483 ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39810916862)). Both sides of `GuestPoll.cpp` are kept: #8483's `PollsAStreamWhosePeerClosed` and this PR's `PollsAHungUpSocketWithoutPollout`, each called from `main()`, and both debt entries. The PR's diff otherwise loses only the `shutdown_nid_postfix` declaration, which `main` now has. On Linux `guest_poll` fails 3 of 3 with `main`'s `Udp.cpp` and passes 10 of 10 with the change; on Windows it passes both ways. The libc and libkernel suites pass on both runners. The libc and libkernel suites 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. - **xXPBSXx's run** ([comment](https://github.com/boykopovar/AnyPS5/pull/9512#issuecomment-6331790883)): WSL2 Ubuntu 24.04 (a virtualised kernel), GCC 13.3.0, Release, the PR head alone on its merge base a6dcea9279. `guest_poll` passes 3 of 3, and with `Udp.cpp` at the merge base and the PR's tests kept, it aborts. - 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: #7605 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-22 00:09:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T00:09:00Z.

Review: CHANGES_REQUESTED


The Linux behavior change and regression scenario are narrowly targeted, but the live overlap scan requires follow-up before merge. It reports overlaps with #7605 and #8483; I compared the heads directly with git merge-tree and confirmed both combinations currently conflict in docs/dev/debt/libkernel.md, while #8483 also conflicts in core/libs/tests/GuestPoll.cpp at the adjacent test insertion point. The #8483 behavior is Windows-specific and this PR’s code change is Linux/macOS-only, so this appears composable, but the repository rule still requires agreeing on merge order and declaring Depends on accordingly. Please coordinate with those PR authors, resolve the resulting doc/test hunks, and update the checklist from Depends on: none. I found no code correctness blocker in the reviewed Linux path. The PR reports focused Linux and Windows test results and current eligibility/intake/convention/label/report checks pass; I did not run tests locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5607734038 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9512#pullrequestreview-5607734038). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T00:09:00Z. **Review:** CHANGES_REQUESTED --- The Linux behavior change and regression scenario are narrowly targeted, but the live overlap scan requires follow-up before merge. It reports overlaps with #7605 and #8483; I compared the heads directly with `git merge-tree` and confirmed both combinations currently conflict in `docs/dev/debt/libkernel.md`, while #8483 also conflicts in `core/libs/tests/GuestPoll.cpp` at the adjacent test insertion point. The #8483 behavior is Windows-specific and this PR’s code change is Linux/macOS-only, so this appears composable, but the repository rule still requires agreeing on merge order and declaring `Depends on` accordingly. Please coordinate with those PR authors, resolve the resulting doc/test hunks, and update the checklist from `Depends on: none`. I found no code correctness blocker in the reviewed Linux path. The PR reports focused Linux and Windows test results and current eligibility/intake/convention/label/report checks pass; I did not run tests locally.
EagleBearerYS commented 2026-10-22 00:41:10 +00:00 (Migrated from github.com)

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


Thanks, @MarcZX10. This PR now goes after #7605: Depends on lists it, and I've left a note there. #8483 is the duplicate of #9492, which is being settled with its author and the maintainers. This PR merges cleanly with #9492 (git merge-tree of the two heads), and if #8483 is the one that goes in, this PR goes after it and resolves the GuestPoll.cpp and debt-file hunks on rebase. The Overlap line in the description now gives the order.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329838119 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9512#issuecomment-6329838119). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-22T00:41:10Z. --- Thanks, @MarcZX10. This PR now goes after #7605: Depends on lists it, and I've left a note there. #8483 is the duplicate of #9492, which is being settled with its author and the maintainers. This PR merges cleanly with #9492 (`git merge-tree` of the two heads), and if #8483 is the one that goes in, this PR goes after it and resolves the `GuestPoll.cpp` and debt-file hunks on rebase. The Overlap line in the description now gives the order.
MarcZX10 commented 2026-10-22 01:17:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T01:17:44Z.

Review: APPROVED


Re-reviewed the current Linux-specific change and its updated overlap note. The code clears POLLOUT only when the returned events include POLLHUP, matching the cited FreeBSD poll rule; the PR clearly records that Windows retains WSAPoll behavior and that #8483 is mutually exclusive with #9492. The author reports Linux regressions and registered libc/libkernel suites, and current hosted checks are green. I did not run a local build. The previous order/coordination finding is resolved.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5608161033 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9512#pullrequestreview-5608161033). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T01:17:44Z. **Review:** APPROVED --- Re-reviewed the current Linux-specific change and its updated overlap note. The code clears `POLLOUT` only when the returned events include `POLLHUP`, matching the cited FreeBSD poll rule; the PR clearly records that Windows retains WSAPoll behavior and that #8483 is mutually exclusive with #9492. The author reports Linux regressions and registered libc/libkernel suites, and current hosted checks are green. I did not run a local build. The previous order/coordination finding is resolved.
MarcZX10 commented 2026-10-22 02:06:00 +00:00 (Migrated from github.com)

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

Review: APPROVED


Rechecked the current head and the author’s overlap update. #7605 is now an explicit dependency; the #8483/#9492 mutually exclusive Windows change and alternate rebase order are documented. The Linux code clears POLLOUT only when a stream socket reports POLLHUP, matching the cited FreeBSD pollscan rule; the regression is Linux-focused and reports 10 consecutive passes, with broader libc/libkernel suites reported on Linux and Windows. Current eligibility, conventions, intake, labels and report checks pass. Product jobs are skipped. I did not run local tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5608448484 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9512#pullrequestreview-5608448484). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T02:06:00Z. **Review:** APPROVED --- Rechecked the current head and the author’s overlap update. #7605 is now an explicit dependency; the #8483/#9492 mutually exclusive Windows change and alternate rebase order are documented. The Linux code clears `POLLOUT` only when a stream socket reports `POLLHUP`, matching the cited FreeBSD `pollscan` rule; the regression is Linux-focused and reports 10 consecutive passes, with broader libc/libkernel suites reported on Linux and Windows. Current eligibility, conventions, intake, labels and report checks pass. Product jobs are skipped. I did not run local tests.
xXPBSXx commented 2026-10-22 03:15:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-22T03:15:05Z.


Linux data point for 38e4c5e36c: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal), GCC 13.3.0, Release, BUILD_TESTING=ON, PR head alone (not merged onto main; its merge-base is a6dcea927).

  • With the PR: ctest -R '^guest_poll$' passes 3 of 3.
  • With libkernel/Socket/src/Udp.cpp restored to the merge-base (the PR's tests kept): fails (Subprocess aborted).
    Not tested: macOS, Windows, a title run.
    AI-assisted (Claude Code).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6331790883 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9512#issuecomment-6331790883). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-22T03:15:05Z. --- Linux data point for `38e4c5e36c`: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal), GCC 13.3.0, Release, `BUILD_TESTING=ON`, PR head alone (not merged onto `main`; its merge-base is `a6dcea927`). - With the PR: `ctest -R '^guest_poll$'` passes 3 of 3. - With `libkernel/Socket/src/Udp.cpp` restored to the merge-base (the PR's tests kept): fails (`Subprocess aborted`). Not tested: macOS, Windows, a title run. AI-assisted (Claude Code).
EagleBearerYS commented 2026-10-22 03:20:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T03:20:42Z.


@xXPBSXx thanks for the Linux run, both red and green. It's in Tested now.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6331858290 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9512#issuecomment-6331858290). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-22T03:20:42Z. --- @xXPBSXx thanks for the Linux run, both red and green. It's in Tested now.
MarcZX10 commented 2026-10-22 04:20:52 +00:00 (Migrated from github.com)

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

Review: DISMISSED


The Linux poll behavior and reported red/green regression remain consistent with the earlier review; the overlap note now declares #7605 and documents the alternative order with #8483/#9492. One repository requirement remains: the branch and reported tests are based on main a6dcea9279, while current upstream main is c61d20f548. Please update the branch and rerun the focused poll test, conventions, and overlap check on the current base. The author-reported WSL results are not a rerun on the updated head; I did not run tests locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609220573 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9512#pullrequestreview-5609220573). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:20:52Z. **Review:** DISMISSED --- The Linux poll behavior and reported red/green regression remain consistent with the earlier review; the overlap note now declares #7605 and documents the alternative order with #8483/#9492. One repository requirement remains: the branch and reported tests are based on main a6dcea9279, while current upstream main is c61d20f54801efc3798555829f6fedcff71ad7ff. Please update the branch and rerun the focused poll test, conventions, and overlap check on the current base. The author-reported WSL results are not a rerun on the updated head; I did not run tests locally.
EagleBearerYS commented 2026-10-22 05:03:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T05:03:54Z.


Thanks, @MarcZX10. The branch now has main at ab347d144d merged in (1983ed955d), and the PR's own diff is unchanged. On GitHub's runners (run) guest_poll fails on Linux with main's Udp.cpp and passes 10 runs in a row with the change, and the libc and libkernel suites pass on both runners. Conventions pass, and the overlap check finds the same three PRs the description lists. Tested now says so.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6333163752 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9512#issuecomment-6333163752). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-22T05:03:54Z. --- Thanks, @MarcZX10. The branch now has `main` at ab347d144d merged in (1983ed955d), and the PR's own diff is unchanged. On GitHub's runners ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39723082925)) `guest_poll` fails on Linux with `main`'s `Udp.cpp` and passes 10 runs in a row with the change, and the libc and libkernel suites pass on both runners. Conventions pass, and the overlap check finds the same three PRs the description lists. Tested now says so.
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!9512
No description provided.