Skip to content

System.Native: Stop using EV_RECEIPT in the kevent code - #130372

Merged
wfurt merged 1 commit into
dotnet:mainfrom
arrowd:kevent-ev-receipt
Jul 23, 2026
Merged

wfurt merged 1 commit into
dotnet:mainfrom
arrowd:kevent-ev-receipt

Conversation

@arrowd

@arrowd arrowd commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

The EV_RECEIPT is used for two reasons:

  1. If we want to know specifically which events from changelist have failed to register. This is not the case for us, as we're passing eventlist=NULL and nevents=0
  2. If we want to stop processing changelist after the first error encountered. This is achieved by passing nevents=0, like this code does, but it doesn't really want that. Avoiding passing EV_RECEIPT allows to remove the FreeBSD/OpenBSD hack that was trying to accomodate for the behavior caused by passing the flag.

This solution is explained in #26633 (comment) and https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=229741#c6

@sec @buzuka @wfurt

…king

The EV_RECEIPT is used for two reasons:
1. If we want to know specifically which events from changelist have failed to
   register. This is not the case for us, as we're passing eventlist=NULL and
   nevents=0
2. If we want to stop processing changelist after the first error encountered.
   This is achieved by passing nevents=0, like this code does, but it doesn't
   really want that. Avoiding passing EV_RECEIPT allows to remove the
   FreeBSD/OpenBSD hack that was trying to accomodate for the behavior caused
   by passing the flag.

This solution is explained in dotnet#26633 (comment)
and https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=229741#c6
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jul 8, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@teo-tsirpanis

Copy link
Copy Markdown
Contributor

Should we unlock and reopen #26633 and mark this PR as closing it?

@arrowd

arrowd commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

That makes sense to me, yes.

@github-actions

github-actions Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow state for the Holistic Review Orchestrator.

{
  "version": 5,
  "last_dispatched_commit": "43f932ca212493ef9e151772c4a5f1512ab81606",
  "last_dispatched_base_ref": "main",
  "last_dispatched_base_sha": "7abe5f60c079129a57c358451cfe01ee198fa40f",
  "last_reviewed_commit": "43f932ca212493ef9e151772c4a5f1512ab81606",
  "last_reviewed_base_ref": "main",
  "last_reviewed_base_sha": "7abe5f60c079129a57c358451cfe01ee198fa40f",
  "last_recorded_worker_run_id": "29680701695",
  "review_attempt_commit": "",
  "review_attempt_base_ref": "",
  "review_attempt_count": 0,
  "max_review_attempts": 5,
  "review_history_format": "holistic-review-disclosure-v1",
  "review_history": [
    {
      "commit": "43f932ca212493ef9e151772c4a5f1512ab81606",
      "review_id": 4730521945
    }
  ]
}

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Holistic Review

Motivation: Justified. The EV_RECEIPT flag provides no benefit here because the code passes eventlist=NULL and nevents=0, and it was the direct cause of the FreeBSD/OpenBSD arming bug (#30698) that required the special-cased split kevent() workaround. Removing it addresses the root cause rather than the symptom, and the reasoning is well-documented via the linked FreeBSD bug and #26633 discussion.

Approach: Correct. Dropping EV_RECEIPT from AddFlags/RemoveFlags lets the read and write filters be armed in a single kevent() call again, which allows the #if defined(__FreeBSD__) || defined(__OpenBSD__) split-call hack to be removed entirely. The remaining logic (building up to two struct kevent entries and issuing one kevent() with EINTR retry) is unchanged and internally consistent. No dangling references to EV_RECEIPT remain in the file.

Summary: ⚠️ Needs Human Review. The code change itself is clean, minimal, and correct for what it does, and the rationale for FreeBSD/OpenBSD is sound. The one point worth a human confirming is that this also changes behavior on other kqueue platforms (notably macOS), which previously compiled EV_RECEIPT into the flags. With nevents=0/eventlist=NULL, EV_RECEIPT was effectively inert on those platforms (there is no event list for it to populate), so removal should be behavior-neutral there, but a maintainer familiar with the macOS socket async path should confirm error-propagation semantics are unaffected. No blocking issues found; the community contributor's explanation is convincing.

Detailed Findings

✅ Correctness: The changelist is still processed atomically in a single kevent() call, and error handling (EINTR retry loop, SystemNative_ConvertErrorPlatformToPal(errno)) is preserved. Removing the FreeBSD/OpenBSD split-call path eliminates the code that reset i = 0 mid-function, simplifying control flow without altering the general path.

✅ Scope / cleanliness: Change is tightly scoped to the two flag constants and the platform-specific hack. No unrelated edits.

💡 Verification: Since this affects async connect-completion delivery, it would be worth confirming via CI or a manual run that FreeBSD async connect no longer hangs and macOS socket event registration still reports registration errors as before.

Note

This review was generated by this repository's Holistic Review agentic workflow to complement the built-in Copilot review.

Generated by Holistic Review · 44.7 AIC · ⌖ 10.4 AIC · ⊞ 10K

@wfurt wfurt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@wfurt
wfurt merged commit 46e1d77 into dotnet:main Jul 23, 2026
144 of 148 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Jul 24, 2026
@arrowd
arrowd deleted the kevent-ev-receipt branch July 29, 2026 15:20
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 29, 2026

This branch had an error being deployed

1 failed deployment
copilot-pat-pool — 43f932ca Deployed Jul 8, 2026 by teo-tsirpanis via conclusion #4657
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Net.Sockets community-contribution Indicates that the PR has been added by a community member os-freebsd FreeBSD OS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants