fix(libkernel): report a reset stream socket polled for no event as hung up on macOS #20161

Open
imellag wants to merge 1 commit from upstream-pr/20161 into main
imellag commented 2026-11-14 18:40:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-11-14T18:40:12Z.


What

guest_poll aborts on macOS on main in the reset-stream case that #11247 added from a PS5 measurement: after the peer resets the connection, poll asking for no event must return 1 with POLLHUP. XNU's poll never reports anything for a socket polled for no event, even after a reset, while the same socket polled for POLLIN reports POLLIN|POLLHUP. A host program on macOS 27.2 shows it (peer closed with SO_LINGER {1, 0}):

events 0     r=0 rev=0x0
POLLIN       r=1 rev=0x11
events 0 again r=0 rev=0x0

On macOS, a guest stream socket polled for no event is now asked again with POLLIN at a zero timeout after each host wait, and only the POLLHUP or POLLERR of that answer is kept. That answer goes through the existing ClosedStreamEvents, so a peer's plain close (one direction ended) still reports nothing and does not wake the call, as on FreeBSD; a reset reports POLLHUP. The host wait itself still asks for no event, so readable data does not end the wait early. A socket polls in slices of 10 ms, so a reset during a wait is seen up to 10 ms late; with a zero timeout it is seen at once. Other hosts, libSceNet sockets lent to poll and every socket that asks for an event are unchanged.

The macOS socket debt entry said "a call that asks for no event gets nothing, where FreeBSD reports POLLHUP"; it now records the second query and its delay (still under 1000 characters).

Tested

macOS 27.2, Apple M4 Pro, x86-64 Release under Rosetta 2, main 80b0bdf264.

  • guest_poll on main: aborts at the no-event check after the reset (the POLLIN and POLLIN|POLLOUT checks around it already pass). With the change: passes 3 of 3 runs.
  • ctest -R "poll|socket|select|kevent|kqueue|equeue|sce_net|net_ctl|udp|tcp|linger|connect": 119 of 123 pass; the 4 failures (guest_refused_connect, guest_sce_net, guest_socket_options, guest_socket_port_zero) fail the same way on main on this Mac. In one of three parallel (-j6) runs guest_socket_read_write also failed; it passes 6 of 6 runs alone and only polls for requested events, which this change does not touch.
  • python3 tools/check_conventions.py --base upstream/main passes. tools/pr_overlap.py confirms no overlap; it could not compare docs/dev/debt/libkernel.md with older PRs that conflict with main, and #17853 (Linux pipes) also edits Udp.cpp in a different function.

Not run on Windows or Linux; the change is inside #ifdef __APPLE__.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5314920839 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20161). Originally posted by [imellag](https://github.com/imellag) on 2026-11-14T18:40:12Z. --- ### What `guest_poll` aborts on macOS on `main` in the reset-stream case that #11247 added from a PS5 measurement: after the peer resets the connection, `poll` asking for no event must return 1 with `POLLHUP`. XNU's `poll` never reports anything for a socket polled for no event, even after a reset, while the same socket polled for `POLLIN` reports `POLLIN|POLLHUP`. A host program on macOS 27.2 shows it (peer closed with `SO_LINGER` {1, 0}): ``` events 0 r=0 rev=0x0 POLLIN r=1 rev=0x11 events 0 again r=0 rev=0x0 ``` On macOS, a guest stream socket polled for no event is now asked again with `POLLIN` at a zero timeout after each host wait, and only the `POLLHUP` or `POLLERR` of that answer is kept. That answer goes through the existing `ClosedStreamEvents`, so a peer's plain close (one direction ended) still reports nothing and does not wake the call, as on FreeBSD; a reset reports `POLLHUP`. The host wait itself still asks for no event, so readable data does not end the wait early. A socket polls in slices of 10 ms, so a reset during a wait is seen up to 10 ms late; with a zero timeout it is seen at once. Other hosts, libSceNet sockets lent to `poll` and every socket that asks for an event are unchanged. The macOS socket debt entry said "a call that asks for no event gets nothing, where FreeBSD reports `POLLHUP`"; it now records the second query and its delay (still under 1000 characters). ### Tested macOS 27.2, Apple M4 Pro, x86-64 Release under Rosetta 2, `main` 80b0bdf264. - `guest_poll` on `main`: aborts at the no-event check after the reset (the `POLLIN` and `POLLIN|POLLOUT` checks around it already pass). With the change: passes 3 of 3 runs. - `ctest -R "poll|socket|select|kevent|kqueue|equeue|sce_net|net_ctl|udp|tcp|linger|connect"`: 119 of 123 pass; the 4 failures (`guest_refused_connect`, `guest_sce_net`, `guest_socket_options`, `guest_socket_port_zero`) fail the same way on `main` on this Mac. In one of three parallel (`-j6`) runs `guest_socket_read_write` also failed; it passes 6 of 6 runs alone and only polls for requested events, which this change does not touch. - `python3 tools/check_conventions.py --base upstream/main` passes. `tools/pr_overlap.py` confirms no overlap; it could not compare `docs/dev/debt/libkernel.md` with older PRs that conflict with `main`, and #17853 (Linux pipes) also edits `Udp.cpp` in a different function. Not run on Windows or Linux; the change is inside `#ifdef __APPLE__`. ### 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](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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
kurexw commented 2026-11-16 12:14:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-16T12:14:01Z.

Review: COMMENTED


Tested on macOS 27.2, Apple Silicon (M4), full build (x86-64 under Rosetta 2). This PR was merged alone onto main 04f7633c01 with git merge --no-ff. I ran the 56 socket and net tests (guest_socket_*, guest_poll, guest_refused_connect, guest_sce_net, guest_net_*, guest_kernel_socket*) three times on main and three times with this PR.

  • guest_poll fails in all three runs on main and passes in all three runs with this PR.
  • No other test changes.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5919772555 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20161#pullrequestreview-5919772555). Originally posted by [kurexw](https://github.com/kurexw) on 2026-11-16T12:14:01Z. **Review:** COMMENTED --- Tested on macOS 27.2, Apple Silicon (M4), full build (x86-64 under Rosetta 2). This PR was merged alone onto `main` 04f7633c01 with `git merge --no-ff`. I ran the 56 socket and net tests (`guest_socket_*`, `guest_poll`, `guest_refused_connect`, `guest_sce_net`, `guest_net_*`, `guest_kernel_socket*`) three times on `main` and three times with this PR. - `guest_poll` fails in all three runs on `main` and passes in all three runs with this PR. - No other test changes.
MarcZX10 commented 2026-11-30 10:31:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T10:31:13Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head fd83adbb17dc8d420b13149d468eaf67bb6d768b against the prepared diff. No commands or tests were run.

Results

Check Result Note
Diff and targeted source review passed Both changed files read
Automated checks not run Author-reported results not independently verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

Did not run tests or independently verify the reported macOS behavior. No files were excluded; both files listed as reviewed in the manifest were read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6110523953 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20161#pullrequestreview-6110523953). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-30T10:31:13Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the points below are optional. ## What I ran Reviewed head `fd83adbb17dc8d420b13149d468eaf67bb6d768b` against the prepared diff. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | Both changed files read | | Automated checks | not run | Author-reported results not independently verified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Did not run tests or independently verify the reported macOS behavior. No files were excluded; both files listed as reviewed in the manifest were read. ## To get this to a good state Nothing is required.
NobleBrains commented 2026-12-01 00:21:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NobleBrains on 2026-12-01T00:21:57Z.

Review: APPROVED


Confirmed on macOS 15.

Setup: Apple M4, macOS 15.7.9, Apple clang 17.0.0 (clang-1700.6.3.2), x86_64 Release under Rosetta, BUILD_TESTING=ON. These are the OS and compiler generation of the macos-15 runner.
Tree: main 93d64f2d1e + the open macOS build fixes #27201, #27739, #27843, #17425, #27827, #27767 (main does not build on macOS without them, see #28168), + #22091, #28369, #28075, #28076, #28284, then #17878, #20161, #25134, #26806, #22932, #28373, #27828, #27950, #27582, #24311 merged one after another. All merged cleanly.

guest_poll failures
same tree before this PR 3/3
with this PR at fd83adbb17 0/5

Full ctest -j 6 after all of them: 7047/7066 pass. Compared with the run before the second group of merges, no test fails that passed before.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6122948990 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20161#pullrequestreview-6122948990). Originally posted by [NobleBrains](https://github.com/NobleBrains) on 2026-12-01T00:21:57Z. **Review:** APPROVED --- Confirmed on macOS 15. **Setup:** Apple M4, macOS 15.7.9, Apple clang 17.0.0 (clang-1700.6.3.2), x86_64 Release under Rosetta, `BUILD_TESTING=ON`. These are the OS and compiler generation of the `macos-15` runner. **Tree:** `main` `93d64f2d1e` + the open macOS build fixes #27201, #27739, #27843, #17425, #27827, #27767 (`main` does not build on macOS without them, see #28168), + #22091, #28369, #28075, #28076, #28284, then #17878, #20161, #25134, #26806, #22932, #28373, #27828, #27950, #27582, #24311 merged one after another. All merged cleanly. | `guest_poll` | failures | |---|---| | same tree before this PR | 3/3 | | with this PR at `fd83adbb17` | 0/5 | **Full `ctest -j 6`** after all of them: 7047/7066 pass. Compared with the run before the second group of merges, no test fails that passed before. AI-assisted: yes (Claude Code)
ligmaSec commented 2026-12-03 16:15:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T16:15:28Z.

Review: COMMENTED


The second poll is scoped to the macOS sockets with an empty native event mask. Please move the debt change into a fragment under docs/dev/debt/changes/ so it can be applied without overwriting newer socket debt entries. I reviewed the code path from Linux.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6173698721 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20161#pullrequestreview-6173698721). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T16:15:28Z. **Review:** COMMENTED --- The second poll is scoped to the macOS sockets with an empty native event mask. Please move the debt change into a fragment under `docs/dev/debt/changes/` so it can be applied without overwriting newer socket debt entries. I reviewed the code path from Linux. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/20161:upstream-pr/20161'
git switch 'upstream-pr/20161'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/20161'
git switch 'upstream-pr/20161'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/20161'
git switch 'upstream-pr/20161'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/20161'
git switch 'main'
git merge --squash 'upstream-pr/20161'
git switch 'main'
git merge --ff-only 'upstream-pr/20161'
git switch 'main'
git merge 'upstream-pr/20161'
git push origin 'main'
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!20161
No description provided.