Repository navigation
fix(libkernel): report a pipe closed before poll reads its status flags as POLLNVAL on Linux - #17853
Conversation
…gs as POLLNVAL on Linux poll classified a descriptor as a pipe with fstat and then read its access mode with fcntl(F_GETFL). When another thread closed the pipe between the two calls, fcntl failed with EBADF and poll threw "querying pipe descriptor N failed", which aborts guest_poll on Linux CI. An EBADF from that query now leaves the descriptor unclassified, so the existing recheck reports it as POLLNVAL like a descriptor closed before the call.
|
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.
|
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.
AI-assisted: yes. |
|
Hi @dantdmdarealguy, thank you for investigating this race condition. While the observation regarding the window between
Closing this pull request based on these repository and technical constraints. |
|
Thanks for the review. Taking the points in order:
|
|
Following up on point 4: the |
|
Windows check of head Setup: Windows 11 x64, WinLibs GCC 15.2.0 (r7), Ninja, Release,
AI-assisted: yes. |
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)