Skip to content

SocketPool+kQueue: retry kevent on EINTR instead of failing - #229

Merged
swhitty merged 1 commit into
swhitty:mainfrom
ianegordon:ian/tvt-305-epollgetnotifications-should-retry-on-eintr-rather-than
Jul 22, 2026
Merged

SocketPool+kQueue: retry kevent on EINTR instead of failing#229
swhitty merged 1 commit into
swhitty:mainfrom
ianegordon:ian/tvt-305-epollgetnotifications-should-retry-on-eintr-rather-than

Conversation

@ianegordon

Copy link
Copy Markdown
Contributor

Summary

Applies the same fix as a196c2e (ePoll) to the kQueue backend. kevent(2) documents: "[EINTR] A signal was delivered before the timeout expired and before any events were placed on the kqueue for return." No events are lost — but getNotifications() treated -1/EINTR as fatal, unwinding SocketPool.run() whose defer { cancelAll() } cancels every waiting continuation. A single signal delivery (e.g. Xcode's debugger pausing/resuming the process) tore down the whole pool on Darwin.

Now returns no events so the caller polls again, using the same guard shape and comment as the ePoll fix.

The Poll backend has the same gap, but a fix there interacts with Windows/WSAPoll semantics — see #228 for details and a proposed direction.

Testing

Full suite passes (449 tests, 51 suites). No new test: forcing EINTR requires delivering a signal to the exact thread blocked in kevent, which isn't deterministically arrangeable under Swift Concurrency (the ePoll fix in a196c2e shipped without a test for the same reason).

🤖 Generated with Claude Code

kevent(2) can return -1/EINTR when a signal is delivered before any
events arrive (e.g. debugger pause/resume). getNotifications treated
this as fatal, unwinding SocketPool.run() and cancelling all waiters.
Return no events instead so the caller polls again, matching the
epoll_wait fix in a196c2e.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.89%. Comparing base (4e246d3) to head (58af82c).

Files with missing lines Patch % Lines
FlyingSocks/Sources/SocketPool+kQueue.swift 75.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #229   +/-   ##
=======================================
  Coverage   92.88%   92.89%           
=======================================
  Files          71       71           
  Lines        3727     3731    +4     
=======================================
+ Hits         3462     3466    +4     
  Misses        265      265           

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

@swhitty
swhitty merged commit 3ed8e1b into swhitty:main Jul 22, 2026
11 of 13 checks passed
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