fix(libkernel): throw on an EV_CLEAR EVFILT_WRITE knote with NOTE_LOWAT above 1 on a Linux TCP socket #9843
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9843"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by ebarr24 on 2026-10-22T17:31:59Z.
What
Follow-up to #8596. nikowolf123 showed in review that an EV_CLEAR EVFILT_WRITE knote with a NOTE_LOWAT mark above 1 on a Linux TCP socket can make kevent wait forever: PollEdge disarms the EPOLLET knote while the free space is below the mark, and Linux TCP wakes EPOLLOUT only after a send or poll found the socket not writable (tcp_check_space), where FreeBSD 11's tcp_input.c calls sowwakeup on every ACK that frees send space. AddDescriptorKnote and ModifyKnote now throw NotImplemented for exactly that combination, a test requires the throw and the combinations that stay supported, and the libkernel debt entry keeps the POLLOUT gate and the stream-only write mark as open gaps.
Tested
Windows 11, MinGW-w64 GCC 15.2, Release build with tests.
guest_kqueuepasses with this change; the new test fails onmain.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
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T12:32:04Z.
Review: COMMENTED
Checked against main
87666fc5d6, FreeBSD 11.4sys/kern/uipc_socket.c(filt_sowrite), FreeBSD 11.0sys/netinet/tcp_input.c, and Linux v6.8net/ipv4/tcp_input.c/net/core/sock.c:PollEdgedisarms whenSO_SNDBUF - SIOCOUTQis below the mark whilepollreported POLLOUT, sotcp_pollnever setSOCK_NOSPACEandtcp_check_spacenever wakes the epoll edge. With a mark of 1 the knote only disarms when POLLOUT was missing, so that case is safe. Throwing also looks right to me, since Linux fixesSO_SNDLOWATat 1 and the mark can't be handed to the host.lowWater > 1, EV_CLEAR or an existingPollEdgeknote. A mark of 1, no NOTE_LOWAT, Unix stream and level-triggered knotes are not affected, and UDP above 1 already throws inDescriptorLowWater.EdgeWatch.cpp:42-43already throws "EV_CLEAR on a socket or a pipe off Linux" for every EV_CLEAR socket knote. The new check only runs first and changes the message, so no Windows case that worked before is lost.docs/dev/debt/libkernel.md, because the kqueue entry was rewritten. When resolving it, the new sentence may fit better in the existing "kevent EV_CLEAR on a socket or a pipe" entry, which already citestcp_check_space.EdgeTriggeredTcpWriteLowWateris the only place where the new throw is the first one, and the PR was tested on Windows. Could you runguest_kqueueon a Linux host once after the rebase?Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.