Repository navigation
compat: honor the epoll interest mask in the macOS shim - #202
Merged
wiedehopf merged 1 commit intoNov 4, 2026
Merged
Conversation
epoll_ctl MOD replaces the interest mask, but the shim only ever called EV_ADD and never removed a filter, and with EPOLLIN|EPOLLOUT in the same call the second EV_SET overwrote the first, so only the write filter was submitted. After a client recovered from backpressure, flushClient() clears EPOLLOUT with EPOLL_CTL_MOD. The stale EVFILT_WRITE kept reporting the now writable socket, so epoll_wait() returned immediately on every loop with an empty send queue. Submit both filters, remove the ones a MOD no longer requests, and delete both on DEL, all in a single kevent() call with EV_RECEIPT so every change reports its own result. A missing filter is only an error on DEL when neither was registered, matching the ENOENT epoll semantics the callers already expect.
wiedehopf
approved these changes
Nov 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The macOS epoll shim (
compat/apple/epoll_shim.c) does not translate the epoll interest mask correctly:EPOLLIN | EPOLLOUTin one call, the secondEV_SEToverwrites the first, so only the write filter is submitted;EPOLL_CTL_MODonly ever callsEV_ADD, so a filter that is no longer requested is left registered.Impact
macOS only, no Linux code path is touched.
flushClient()addsEPOLLOUTwithEPOLL_CTL_MODwhen a client's send queue cannot be flushed and removes it again once the queue drains. On kqueue the removal never happened, so the staleEVFILT_WRITEkeeps reporting the now writable socket:epoll_wait()returns immediately on every loop with an empty send queue, and the network thread spins at 100% until that client disconnects.Repro
Small program built against the shim:
Baseline on macOS:
initial=1 idle_after_MOD=1 readable=1, exit 1. Native Linux epoll with the same sequence givesidle_after_MOD=0; with this patch the shim matches Linux.Fix
Build the full change set for both directions and submit it in one
kevent()call withEV_RECEIPT, so every change reports its own result instead of the call stopping at the first error.MODadds/removes each direction to match the requested mask;DELdeletes both and returnsENOENTonly when neither was registered.Verification
epoll_ctlerrors;-W -Wall -Werror;make test(cprtests,crctests) passes.EPOLL_CTL_ADDon an already registered fd andEPOLL_CTL_MODon an unregistered one keep their previous best-effort behavior (noEEXIST/ENOENTtracking). readsb does not rely on either.