Article View: muc.lists.freebsd.bugs
Article #251[Bug 300076] [patch] linuxulator / inotify: epoll_ctl(EPOLLIN | EPOLLOUT) on inotify fd fails with EINVAL, causing EAGAIN busy l...
From: bugzilla-noreply
Date: Sun, 25 Oct 2026 23:59
Date: Sun, 25 Oct 2026 23:59
91 lines
5818 bytes
5818 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300076
Bug ID: 300076
Summary: [patch] linuxulator / inotify: epoll_ctl(EPOLLIN |
EPOLLOUT) on inotify fd fails with EINVAL, causing
EAGAIN busy loop in Go (fsnotify) binaries
Product: Base System
Version: 15.1-RELEASE
Hardware: Any
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: kern
Assignee: bugs@FreeBSD.org
Reporter: harimawo@harimawo.com
Created attachment 276483
--> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=276483&action=edit
Patch for linux_event.c and vfs_inotify.c
[Problem Description]
When running Linux binaries written in Go that use `fsnotify` (inotify) under
FreeBSD 15 Linuxulator, the process enters a tight busy loop consuming 100%+
CPU and rapidly filling logs with:
`fsnotify error: read : resource temporarily unavailable` (EAGAIN).
[Root Cause]
1. `fsnotify` calls `inotify_init1(IN_CLOEXEC | IN_NONBLOCK)` and wraps the
returned descriptor with Go's `os.NewFile(uintptr(fd), "")`.
2. Because `O_NONBLOCK` is set on the descriptor, Go's runtime network poller
(`runtime/netpoll_epoll.go:netpollopen`) attempts to register the fd with
`epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev)` using:
`ev.events = _EPOLLIN | _EPOLLOUT | _EPOLLRDHUP | _EPOLLET`
On Linux, registering both `EPOLLIN` and `EPOLLOUT` on a read-only inotify
descriptor succeeds (write readiness simply never fires).
3. In FreeBSD's Linuxulator (`sys/compat/linux/linux_event.c:epoll_to_kevent`),
`EPOLLIN | EPOLLOUT` is translated into two kevents: `EVFILT_READ` and
`EVFILT_WRITE`.
4. However, `inotify_kqfilter()` in `sys/kern/vfs_inotify.c` only accepts
`EVFILT_READ` and returns `EINVAL` for `EVFILT_WRITE`:
if (kn->kn_filter != EVFILT_READ)
return (EINVAL);
(Note: By contrast, `pipe_kqfilter()` in `sys/kern/sys_pipe.c` handles
unsupported filter directions by attaching a no-op filter `pipe_nfiltops` and
returning 0.)
5. Because `EVFILT_WRITE` fails with `EINVAL`, `linux_epoll_ctl()` fails with
`EINVAL`.
6. Go's `internal/poll.FD.Init()` treats the `epoll_ctl` failure as "not
pollable" (`pollable = false`), while the file descriptor itself remains
non-blocking (`FNONBLOCK`).
7. Subsequent `Read()` calls by `fsnotify` immediately return `EAGAIN` from
`inotify_read()` without parking on `epoll_wait()`, resulting in an infinite
unthrottled `EAGAIN` retry loop.
[How to Reproduce]
Run any Linux Go binary (such as Google Antigravity CLI `agy`) that watches
files/directories with `github.com/fsnotify/fsnotify` under Linuxulator on
FreeBSD 15.1.
[Proposed Fix]
The attached patch addresses the issue in two places:
1. `sys/compat/linux/linux_event.c`: In `epoll_to_kevent()`, mask out
`LINUX_EPOLL_EVRD` if `(fp->f_flag & FREAD) == 0` and mask out
`LINUX_EPOLL_EVWR` if `(fp->f_flag & FWRITE) == 0`. This also prevents the same
issue for other read-only special descriptors such as `timerfd`.
2. `sys/kern/vfs_inotify.c`: In `inotify_kqfilter()`, accept `EVFILT_WRITE`
using a no-op filter (`inotify_nfiltops`) that never fires, matching the
behavior of `pipe_kqfilter()` in `sys/kern/sys_pipe.c`.
[Note / Disclosure]
The root cause analysis and patch creation were conducted using Google
Antigravity CLI with Gemini 4 Argon (High), and the patch has been built and
verified on real FreeBSD 15.1-RELEASE (amd64) hardware.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID:
<bug-300076-227@https.bugs.freebsd.org/bugzilla/>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail From: bugzilla-noreply@freebsd.org Newsgroups: muc.lists.freebsd.bugs Subject: [Bug 300076] [patch] linuxulator / inotify: epoll_ctl(EPOLLIN | EPOLLOUT) on inotify fd fails with EINVAL, causing EAGAIN busy loop in Go (fsnotify) binaries Date: Sun, 25 Oct 2026 23:59:02 +0000 Organization: Newsgate at muc.de e.V. Sender: owner-freebsd-bugs@FreeBSD.org Approved: news-admin@muc.de Distribution: world Message-ID: <bug-300076-227@https.bugs.freebsd.org/bugzilla/> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2"; logging-data="28730"; mail-complaints-to="news-admin@muc.de" X-Original-To: bugs@mlmmj.nyi.freebsd.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792972742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fwBreIwDggStQbkokTHyvx5r9mGl8345w2/8cVnyoZQ=; b=Yeu0eWJySYKM3k7EUr2GXusvNnjz9/cz4hi38rFeJ8YXJWH2ee1YpvLGXNiSjVNXIS/x8z IZysKz8j65pkWOWubfVOW1v7G5OfzvFmK6ocPXtOvB9hSqlfdn5mUKscIF8i3lrdHu1xEA 9C2LzhKcWZo+IkaPCuJAhnxHIhGyKrZHP0JqRpLlzOVq7FwQQKDLoJkIYG6prBybayiaKJ O/zMfYQdv7dwqQZhu3mW/VhyLepvAFZOwt0GoD2N1zOjXcczKOJ/oQUpJ7guA3+raAt+cq 0HJmH+xaPwmDzTsg4iG8qjslnGRylUsNu+bdW1vnEtGDk76dS50fSElHZl/Z+g== X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f Auto-Submitted: auto-generated Precedence: list X-Newsgate-Id: f02c70b8849f+ X-No-Archive: Yes