Skip to content

epoll() candidate fixes#187

Open
lhoward wants to merge 1 commit intoswhitty:mainfrom
PADL:lhoward/186
Open

epoll() candidate fixes#187
lhoward wants to merge 1 commit intoswhitty:mainfrom
PADL:lhoward/186

Conversation

@lhoward
Copy link
Contributor

@lhoward lhoward commented Jan 30, 2026

Possible fix for #186, but note this was done by Claude and I have not reviewed it myself (indeed I don't really know enough about epoll(7) to do so).

@lhoward
Copy link
Contributor Author

lhoward commented Jan 31, 2026

Well, this appears to fix the issue. I'll spend some time trying to understand why so I can de-Claude it next week.

Use epoll(7) edge-triggered mode to return notifications only when events
change.

Fixes: swhitty#186
@codecov
Copy link

codecov bot commented Feb 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.80%. Comparing base (5aac1b7) to head (200ce48).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #187   +/-   ##
=======================================
  Coverage   92.80%   92.80%           
=======================================
  Files          68       68           
  Lines        3448     3448           
=======================================
  Hits         3200     3200           
  Misses        248      248           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lhoward
Copy link
Contributor Author

lhoward commented Feb 1, 2026

I've reviewed Claude's changes, I think they're OK (with a bit of cleaning up), another approach would be to continue using level-triggered mode but with EPOLLONESHOT. Not an expert on this so comments are welcome.

@lhoward
Copy link
Contributor Author

lhoward commented Feb 2, 2026

Standby, test failures with patch.

@lhoward lhoward force-pushed the lhoward/186 branch 2 times, most recently from 200ce48 to 4673ad0 Compare February 2, 2026 05:31
@lhoward
Copy link
Contributor Author

lhoward commented Feb 2, 2026

Hmm, I don't seem to have a fix that both passes tests and solves the high CPU usage issue. I'm going to have spend a bit more time investigating it which may take a while to get around to.

@swhitty
Copy link
Owner

swhitty commented Feb 2, 2026

Thanks for looking into this — edge triggered may be the best solution but it also may require a larger refactor — currently sockets are added to the queue (Kqueue / ePoll) when they are blocked and removed when they are unblocked.

The window of time between receiving EWOULDBLOCK and adding the socket to the queue creates a potential race with Edge triggered here because the socket could becomes unblocked during this time. My understanding is that level triggering avoids this.

If switching to edge triggering we may need to add AsyncSocket instances to the queue when they are created and remove when they are closed — apparently this could be faster because while it will receive more events, it will reduce the number of sys calls...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants