Skip to content

utils/macos/epoll: Fix EV_EOF mapping#567

Merged
slp merged 1 commit intocontainers:mainfrom
nirs:macos-epoll-hangup
Mar 12, 2026
Merged

utils/macos/epoll: Fix EV_EOF mapping#567
slp merged 1 commit intocontainers:mainfrom
nirs:macos-epoll-hangup

Conversation

@nirs
Copy link
Contributor

@nirs nirs commented Mar 1, 2026

The code used EV_CLEAR (edge-trigger flag) as a proxy for the event
direction when mapping EV_EOF to a hangup type. This produced the
wrong type: backend WRITE+EOF got READ_HANG_UP, and eventfd READ+EOF
got HANG_UP.

No impact in practice since the worker treats both HANG_UP and
READ_HANG_UP the same way (fatal error, disable networking).

Use the filter type instead:

  • EVFILT_READ + EV_EOF → READ_HANG_UP (half-close)
  • EVFILT_WRITE + EV_EOF → HANG_UP (connection broken)

Unlike epoll where EPOLLRDHUP must be explicitly registered, kqueue
always reports EV_EOF. The shim does not track registration, so
READ_HANG_UP is always reported on read EOF. Document this as a
known difference from epoll in ctl().

Based on #566

@slp
Copy link
Collaborator

slp commented Mar 9, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly fixes an issue in the macOS epoll shim where EV_EOF was not being mapped correctly to READ_HANG_UP and HANG_UP events. The change now properly uses the event filter type (EVFILT_READ or EVFILT_WRITE) to determine the appropriate hangup type. The associated debug logging and documentation have also been updated to reflect this change. My review includes a suggestion to refactor the new logic to improve its readability and reduce duplication.

@nirs nirs force-pushed the macos-epoll-hangup branch from 85c5fc2 to 740c9bd Compare March 9, 2026 17:18
@nirs nirs marked this pull request as ready for review March 9, 2026 17:19
The code used EV_CLEAR (edge-trigger flag) as a proxy for the event
direction when mapping EV_EOF to a hangup type. This produced the
wrong type: backend WRITE+EOF got READ_HANG_UP, and eventfd READ+EOF
got HANG_UP.

No impact in practice since the worker treats both HANG_UP and
READ_HANG_UP the same way (fatal error, disable networking).

Use the filter type instead:
- EVFILT_READ + EV_EOF  → READ_HANG_UP (half-close)
- EVFILT_WRITE + EV_EOF → HANG_UP (connection broken)

Unlike epoll where EPOLLRDHUP must be explicitly registered, kqueue
always reports EV_EOF. The shim does not track registration, so
READ_HANG_UP is always reported on read EOF. Document this as a
known difference from epoll in ctl().

Signed-off-by: Nir Soffer <nirsof@gmail.com>
@nirs nirs force-pushed the macos-epoll-hangup branch from 740c9bd to d67cf55 Compare March 10, 2026 06:46
Copy link
Collaborator

@dorindabassey dorindabassey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks!

@slp slp merged commit 3323f11 into containers:main Mar 12, 2026
11 checks passed
@nirs nirs deleted the macos-epoll-hangup branch March 12, 2026 12:23
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.

3 participants