Repository navigation
fix: EpollDel of a multishot poll that the kernel already ended - #700
Conversation
On a CQ overflow the kernel ends a multishot poll and queues its last CQE without IORING_CQE_F_MORE. If EpollDel runs before that CQE is processed, POLL_REMOVE gets -ENOENT, no ECANCELED completion follows and pending_epoll_removals_ stays incremented. The queued CQE then calls the callback of an owner that has already unsubscribed and re-arms a poll that nobody removes, so ~UringProactor fails with "Pending epoll removals: 1". EpollDel now clears the entry callback before POLL_REMOVE. Such an entry neither notifies nor re-arms, and the last CQE of its request frees it: ECANCELED from POLL_REMOVE or a multishot poll that the kernel ended. ENOENT is expected and logged at VLOG(1), and EpollDel no longer touches the entry after the wait. Signed-off-by: Volodymyr Yavdoshenko <volodymyr@dragonflydb.io>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
PR Summary by QodoFix EpollDel cleanup when a multishot poll has already ended
AI Description
Merge Risk
|
🤖 Augment PR SummaryClears callbacks before poll removal and frees unsubscribed entries on their final CQE, including kernel-ended multishot polls, preventing stale notifications and leaked polls. 🤖 Was this summary useful? React with 👍 or 👎 |
Code Review by Qodo
1. A callback can use freed captures
|
The test fills the CQ ring with NOPs without reaping, so the kernel ends the poll that an eventfd write wakes, and then calls EpollDel. Without the fix POLL_REMOVE gets ENOENT, the queued last CQE calls back and re-arms the poll, and ~UringProactor fails with "Pending epoll removals: 1". Signed-off-by: Volodymyr Yavdoshenko <volodymyr@dragonflydb.io>
When the CQ overflows, the kernel ends a multishot poll and queues its last CQE without
IORING_CQE_F_MORE. IfEpollDelruns before that CQE is processed,POLL_REMOVEgets-ENOENT, noECANCELEDcompletion follows, andpending_epoll_removals_stays incremented. The queued CQE then calls the callback of an owner that has already unsubscribed (e.g. afterUringSocket::ResetOnRecvHook) and re-arms a poll that nobody removes, which keeps the file referenced; at teardown~UringProactorfails withPending epoll removals: 1. Dragonfly hits this inClientKillTest.KillDuringConnectionMigration, which runs on a 16-entry ring.Changes:
EpollDelclears the entry callback beforePOLL_REMOVE, so the owner gets no notifications after it unsubscribes.pending_epoll_removals_, whether that CQE isECANCELEDfromPOLL_REMOVEor the end of a multishot poll by the kernel.-ENOENTfromPOLL_REMOVEis expected and logged atVLOG(1);EpollDelno longer touches the entry after the wait, since it may already be freed.FiberTest.EpollDelAfterKernelEndedPollreproduces it deterministically: it fills the CQ ring with NOPs without reaping, so the kernel ends the poll that an eventfd write wakes, and then callsEpollDel. Without the fix it fails on every run with the same signature as Dragonfly'sClientKillTest.KillDuringConnectionMigration(EpollDel: unexpected result <fd> -2, callbacks afterEpollDel,Pending epoll removals: 1); with it, both tests pass.