Repository navigation
fix(libSceNet): wake a receive on an unbound datagram socket at shutdown on macOS - #10052
Conversation
…own on macOS On macOS, shutdown(SHUT_RD) on a UDP socket that was never bound does not wake a thread blocked in recv on it, so sceNetShutdown left the receiver hanging. Use the receive wait that Windows already has: block on the socket table until the socket gets a local port or is shut, then poll. On macOS an unbound socket reports port 0 from getsockname, so the check looks at the port instead of the Winsock error. Ported from boykopovar#8658. Co-authored-by: Himansh Raj <iamthehimansh@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
guest_sce_net |
|
|---|---|
| Without this change | Subprocess aborted (in CheckUnboundDatagramShutdown) |
| With this change | Passed |
Same machine as above: Apple M1 Pro, macOS 27.0.1, x86_64 build under Rosetta 2.
AI-assisted: yes (Claude Code applied the commits, ran the tests and wrote this comment).
|
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.
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.
|
|
On the overlap report:
AI-assisted: yes (Claude Code ran the merge check and wrote this comment). |
|
OK. I re-derived the structure from the branch rather than trusting the description: the macOS arm is an extension of the existing Windows wait, and Linux is untouched.
Envelope: current Disclosure: Windows host; structure, guards, diff, and test registration all checked locally. The macOS runtime behavior is author-reported, as noted above. Nothing needs to change for merge — flagging only that the validating evidence lives on a macOS runner, not in this review. |
What
On macOS,
sceNetShutdown(s, 0)on a UDP socket that was never bound does not wake a thread blocked insceNetRecvfromon it: the hostshutdown(SHUT_RD)does not interrupt the blockedrecvfrom, so the receiver hangs.Windows already avoids the host receive in this case:
wait_for_local_addresswaits on the socket table until a bind, connect or send gives the socket a local address, or until a shutdown, abort or close ends the wait. This PR turns that path on for macOS:has_local_addresson macOS checks the port fromgetsockname, since an unbound socket reports port 0 there instead of failing withWSAEINVAL.wait_for_datagramusespollinstead ofWSAPoll.sceNetConnect,sceNetRecv,sceNetRecvfrom,sceNetSendtoandsceNetRecvmsgare enabled for__APPLE__as well as_WIN32.docs/dev/debt/libSceNet.mdentry for this wait now names macOS.The Windows and Linux code paths are unchanged.
The code is ported from #8658 by @iamthehimansh (credited as co-author on the commit). This PR splits out only this fix, so it can be reviewed and merged on its own.
Tested
Apple M1 Pro, macOS 27.0.1, x86_64 build under Rosetta 2.
mainalone does not build on macOS yet (libc, fixed by #4627), so I tested on mugurc's macOS series (ci/macos-series-2,27e968974) with this change applied. The changed lines and the helpers they use are identical to this branch.guest_sce_net, with the test object rebuilt at-O0 -gand a breakpoint onabort: without the change it stops inCheckUnboundDatagramShutdown, at the check that the receive returned 0 within 1 s ofsceNetShutdown. With the change that check passes, and the test stops later at asceNetResolverStartNtoa6check thatmainalready changed in 548aecf, which the series does not include.ctest -R 'net|sock|udp|tcp|poll|ssl|http|epoll|refused|resolver'), with and without the change: the same failures in both runs (guest_sce_net,guest_ssl_transport_kernel,guest_ssl_transport_net).guest_refused_connectalso failed in the run without the change; it fails intermittently on this machine.Not tested on Windows or Linux. Their code is unchanged apart from the
#iflines.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code