libkernel: recv after shutdown(SHUT_RD) fails with EPIPE and a zero-length recv on a stream socket blocks (Windows) #8491

Closed
opened 2026-10-20 13:46:56 +00:00 by xXPBSXx · 1 comment
xXPBSXx commented 2026-10-20 13:46:56 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T13:46:56Z.


Repro

Windows host, connected stream pair. (1) shutdown(a, SHUT_RD), then recv(a, buf, 8, 0). (2) recv(a, buf, 0, 0) with nothing queued.
Expected (FreeBSD 11.4 soreceive_generic, sys/kern/uipc_socket.c): (1) 0 (SBS_CANTRCVMORE, Z.1556-1562); (2) 0 without waiting (uio_resid == 0, Z.1575-1578), ENOTCONN on a socket that is not connected (Z.1566-1572).
Actual: (1) -1/EPIPE (32), the Winsock WSAESHUTDOWN; (2) the call blocks until data arrives, as Winsock does for a zero-byte receive.
Test: core/libs/tests/GuestTcp.cpp (ReceiveAnsweredWithoutTheHost, new; aborts before the fix).
Fix branch: https://github.com/xXPBSXx/AnyPS5/tree/fix/recv-after-shutdown-and-empty
AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5942821805 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8491). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T13:46:56Z. --- ### Repro Windows host, connected stream pair. (1) `shutdown(a, SHUT_RD)`, then `recv(a, buf, 8, 0)`. (2) `recv(a, buf, 0, 0)` with nothing queued. Expected (FreeBSD 11.4 `soreceive_generic`, sys/kern/uipc_socket.c): (1) 0 (`SBS_CANTRCVMORE`, Z.1556-1562); (2) 0 without waiting (`uio_resid == 0`, Z.1575-1578), `ENOTCONN` on a socket that is not connected (Z.1566-1572). Actual: (1) -1/EPIPE (32), the Winsock `WSAESHUTDOWN`; (2) the call blocks until data arrives, as Winsock does for a zero-byte receive. Test: `core/libs/tests/GuestTcp.cpp` (`ReceiveAnsweredWithoutTheHost`, new; aborts before the fix). Fix branch: https://github.com/xXPBSXx/AnyPS5/tree/fix/recv-after-shutdown-and-empty AI-assisted (Claude Code).
Filip722 commented 2026-10-21 09:46:00 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Filip722 on 2026-10-21T09:46:00Z.


Linux results distinguish the two parts of this report: zero-length receives also block here; the empty SHUT_RD case returns EOF rather than Windows' EPIPE. There is an additional queued-data distinction below.

Tested unchanged upstream main b5d763770a8e932b35db9bea1c415e7e0ac50a22 in a separate validation checkout. Environment: Debian GNU/Linux 13.7 (trixie), x86-64, kernel 7.2.9-x64v3-xanmod1, AMD Ryzen 5 7640HS, GCC/G++ 15.2.0, CMake 3.31.6/Ninja. Full project configuration: Release, BUILD_TESTING=ON, ANYPS5_RELINKER_ONLY=OFF, ANYPS5_USE_SYSTEM_DEPS=OFF; rebuilt libc, libkernel and libkernel_sys. Temporary probes linked directly to these freshly built, unpatched runtime libraries, as the repository runtime tests do. No production source changes.

Reproduction: fresh real IPv4 TCP loopback pair for each case, using the guest socket/bind/listen/connect/accept APIs. Called both recv_nid_postfix and recvfrom_nid_postfix with a valid buffer. Results were the same for both APIs:

Case Actual Linux guest result
Connected, empty stream, size 0, flags 0 Still blocked when the isolated child was killed at the 1-second deadline, after its pre-call readiness marker
Same, but peer sends one byte after 250 ms Returns 0 after about 250.1–250.2 ms; a subsequent receive still reads that byte
Connected, empty stream, size 0, guest MSG_DONTWAIT (0x80) -1, guest errno 35 (EAGAIN)
Unconnected stream, size 0, 0x80 -1, guest errno 57 (ENOTCONN)
shutdown(receiver, SHUT_RD), empty stream, receive up to 8 bytes 0 immediately
shutdown(receiver, SHUT_RD), peer then sends x, receive up to 8 bytes 1 byte, x

For recvfrom, successful cases set the sender-address length to 0. A focused syscall trace confirms the last result comes from forwarding to Linux:

shutdown(fd, SHUT_RD) = 0
sendto(peer, "x", 1, 0, NULL, 0) = 1
recvfrom(fd, "x", 8, 0, NULL, NULL) = 1

Thus zero-length blocking is not Windows-only, while the post-shutdown EPIPE itself did not reproduce on this Linux setup. The delayed-send control establishes that the zero-length call waits for readiness and does not consume the byte. The last row also differs from #8492's proposed unconditional EOF after guest receive shutdown.

Existing guest_tcp passes; it does not cover these zero-length cases on main. Scope: unchanged-main observations only, not validation of #8492 or an independent measurement of console/FreeBSD semantics. recvmsg, Windows, GPU and title execution were not tested.

AI-assisted: yes (Codex); I am responsible for the reported investigation and results.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6312974744 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8491#issuecomment-6312974744). Originally posted by [Filip722](https://github.com/Filip722) on 2026-10-21T09:46:00Z. --- Linux results distinguish the two parts of this report: zero-length receives also block here; the empty `SHUT_RD` case returns EOF rather than Windows' `EPIPE`. There is an additional queued-data distinction below. Tested unchanged upstream `main` **`b5d763770a8e932b35db9bea1c415e7e0ac50a22`** in a separate validation checkout. Environment: Debian GNU/Linux 13.7 (trixie), x86-64, kernel `7.2.9-x64v3-xanmod1`, AMD Ryzen 5 7640HS, GCC/G++ 15.2.0, CMake 3.31.6/Ninja. Full project configuration: `Release`, `BUILD_TESTING=ON`, `ANYPS5_RELINKER_ONLY=OFF`, `ANYPS5_USE_SYSTEM_DEPS=OFF`; rebuilt `libc`, `libkernel` and `libkernel_sys`. Temporary probes linked directly to these freshly built, unpatched runtime libraries, as the repository runtime tests do. No production source changes. Reproduction: fresh real IPv4 TCP loopback pair for each case, using the guest `socket`/`bind`/`listen`/`connect`/`accept` APIs. Called both `recv_nid_postfix` and `recvfrom_nid_postfix` with a valid buffer. Results were the same for both APIs: | Case | Actual Linux guest result | |---|---| | Connected, empty stream, size 0, flags 0 | Still blocked when the isolated child was killed at the 1-second deadline, after its pre-call readiness marker | | Same, but peer sends one byte after 250 ms | Returns 0 after about 250.1–250.2 ms; a subsequent receive still reads that byte | | Connected, empty stream, size 0, guest `MSG_DONTWAIT` (`0x80`) | -1, guest errno 35 (`EAGAIN`) | | Unconnected stream, size 0, `0x80` | -1, guest errno 57 (`ENOTCONN`) | | `shutdown(receiver, SHUT_RD)`, empty stream, receive up to 8 bytes | 0 immediately | | `shutdown(receiver, SHUT_RD)`, peer then sends `x`, receive up to 8 bytes | 1 byte, `x` | For `recvfrom`, successful cases set the sender-address length to 0. A focused syscall trace confirms the last result comes from forwarding to Linux: ```text shutdown(fd, SHUT_RD) = 0 sendto(peer, "x", 1, 0, NULL, 0) = 1 recvfrom(fd, "x", 8, 0, NULL, NULL) = 1 ``` Thus zero-length blocking is **not Windows-only**, while the post-shutdown `EPIPE` itself did not reproduce on this Linux setup. The delayed-send control establishes that the zero-length call waits for readiness and does not consume the byte. The last row also differs from #8492's proposed unconditional EOF after guest receive shutdown. Existing `guest_tcp` passes; it does not cover these zero-length cases on main. Scope: unchanged-main observations only, not validation of #8492 or an independent measurement of console/FreeBSD semantics. `recvmsg`, Windows, GPU and title execution were not tested. AI-assisted: yes (Codex); I am responsible for the reported investigation and results.
Sign in to join this conversation.
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#8491
No description provided.