Skip to content

Fix FreeBSD: EVFILT_USER wakeup lost when event loop is idle - #260

Open
mstdokumaci wants to merge 1 commit into
uNetworking:masterfrom
mstdokumaci:freebsd-eventing-fix
Open

Fix FreeBSD: EVFILT_USER wakeup lost when event loop is idle#260
mstdokumaci wants to merge 1 commit into
uNetworking:masterfrom
mstdokumaci:freebsd-eventing-fix

Conversation

@mstdokumaci

Copy link
Copy Markdown

Problem
On FreeBSD, us_internal_async_wakeup re-registered the EVFILT_USER filter on every call with EV_ADD|EV_ONESHOT. That registration never fires while the loop is idle in kevent(): the trigger is silently lost, and the wakeup is only picked up once something unrelated causes the loop to iterate again — delaying cross-thread wakeups.

Fix
Register EVFILT_USER once, persistently, in us_internal_async_set with EV_ADD|EV_CLEAR. us_internal_async_wakeup then just fires a bare NOTE_TRIGGER against the existing registration instead of re-adding the filter each time.

Scope
epoll is untouched — this only affects the kqueue backend.

Register the EVFILT_USER async filter persistently (EV_ADD|EV_CLEAR) in us_internal_async_set and trigger it with a bare NOTE_TRIGGER in us_internal_async_wakeup. The previous per-wakeup EV_ADD|EV_ONESHOT never fires in an idle loop on FreeBSD: the trigger is silently lost, and the loop only iterates on unrelated later activity, delaying cross-thread wakeups. Epoll path untouched.
@uNetworkingAB

Copy link
Copy Markdown
Contributor

Does this issue exist for macOS as well?

@mstdokumaci

Copy link
Copy Markdown
Author

Does this issue exist for macOS as well?

No, it is only reproducible on FreeBSD; on macOS, eventing works fine with or without this fix.

@uNetworkingAB

Copy link
Copy Markdown
Contributor

Okay well then it's not really a bug issue, but a request to support FreeBSD, which we don't. There isn't even any FreeBSD runners on GitHub Actions so we cannot even easily run tests on that platform and Node.js do not support it and pretty sure Deno & Bun don't either.

@mstdokumaci

Copy link
Copy Markdown
Author

Okay well then it's not really a bug issue, but a request to support FreeBSD, which we don't. There isn't even any FreeBSD runners on GitHub Actions so we cannot even easily run tests on that platform and Node.js do not support it and pretty sure Deno & Bun don't either.

Agreed, I actually came across this while runinng bun on FreeBSD, because bun have a binary for FreeBSD on the release page: https://github.com/oven-sh/bun/releases . Do you think it is worth adding a bun on FreeBSD action runner? I can give it a try and see what else comes out. Your call, since FreeBSD is not oficially supported.

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