fix(libkernel): report a pipe closed before poll reads its status flags as POLLNVAL on Linux #17853
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17853"
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 dantdmdarealguy on 2026-11-09T18:20:12Z.
What
guest_pollstill aborts on Linux CI after #16626, now with a different message. Run 42602115865 (job 129110707167, mainc0d23c29c1, 2026-11-09 10:36Z) failed with:On Linux,
polldecides that a descriptor is a pipe inIsPipe(Socket/src/Udp.cpp) in two steps:fstatreports a FIFO.fcntl(F_GETFL)then reads the access mode.PollsAPipeClosedDuringTheWaitcloses the read end from the main thread while the waiter thread is insidepoll. If the close lands between those two calls,fcntlfails withEBADFandpollthrows.#16626 handled the case where
fstatalready sees the descriptor closed: the caller rechecksDescriptorIsOpenand reportsPOLLNVAL. This change handles the case where the close happens afterfstat. AnEBADFfrom theF_GETFLquery now leaves the descriptor unclassified, so the same recheck reportsPOLLNVAL, as it does for a descriptor closed before the call. Any otherfcntlfailure still throws.The new Linux test case
PollsAPipeClosedBeforeItsStatusQueryinGuestPoll.cppremoves the timing from the race. The test executable interposesfcntland closes the pipe throughclosejust before libkernel'sF_GETFLquery, then requirespollto return 1 withPOLLNVAL.GuestPosixSpawnFlags.cppandGuestRuntimeLifecycle.cppinterpose libc the same way.guest_poll_testsnow also links${CMAKE_DL_LIBS}fordlsym.Tested
Windows 11 Pro, Intel Core i9-14900K, 128 GB RAM, NVIDIA GeForce RTX 5080 (driver 32.0.16.1742). Windows build: WinLibs GCC 15.2.0, Release. Linux build: Arch Linux on WSL2, GCC 16.1.1, glibc 2.43, Release.
New test on Linux.
ctest -R '^guest_poll$':mainee63f5e8d5with only the test added, it fails every time with the CI messagepoll: querying pipe descriptor 7 failed(100/100 runs).Race without the interposer. A local program, not part of this PR, has a waiter thread call
poll(pipe read end, POLLIN, 0)in a loop while the main thread closes the read end after a varying spin. It does this 2000 times per run.mainpoll: querying pipe descriptor 6 failed)Over all runs,
pollreturned only 0, or 1 withPOLLNVAL.Unmodified
guest_pollon Linux, 16 runs at a time.main: 0/700. That includes 300 runs with 16 busy-loop processes for load. The window is about a microsecond, and CI hits it in about 2 of 300 Linux jobs.Windows. The Windows pipe path is not changed and the new case is Linux-only.
ctest -R '^guest_poll$' --repeat until-fail:100: 100/100 pass onmainand 100/100 with the change.ctest -R "^guest_poll$|patched_libraries": passes.--target libssucceed with no warnings in the touched files.tools/check_test_registration.py,tools/check_conventions.py --base origin/mainandtools/pr_overlap.pypass. No open PR changesIsPipeor this test.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)