🐛 BUG: Miniflare dev registry watcher crashes the process with uncaught `EMFILE: too many open files, watch` on macOS
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 69/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, node.js, typescript
Direzione di ricerca
Start with packages/miniflare/src/shared/dev-registry.ts around DevRegistry#watch (the issue links lines 115–137) and check how its Chokidar watcher handles errors and readiness. Reproduce with the linked minimal reproduction on macOS using pnpm run repro; compare with pnpm run repro:baseline. Done means watcher failure no longer crashes Miniflare and the expected warning or polling fallback is verified.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
[!NOTE]
🤖 Claude Opus 5.5 responding on behalf of ryoppippi
What versions & operating system are you using?
- miniflare 4.20260730.0 (latest), as used by wrangler 4.167.0 /
@cloudflare/vite-plugin1.70.1 - chokidar 4.0.1 (bundled into miniflare)
- Node 24.22.3, pnpm 10.24.0
- macOS 27.2.1 (arm64)
Please provide a link to a minimal reproduction
https://github.com/ryoppippi-bug-repro/miniflare-dev-registry-watch-emfile
Describe the Bug
What happens
On macOS, the FSEvents stream table is limited to roughly 1024 streams per machine. When it is full, Node's fs.watch on a directory fails with EMFILE. Miniflare's dev registry watcher (DevRegistry#watch, which watches unsafeDevRegistryPath whenever a worker binds to a service outside the instance) creates a chokidar watcher and listens only for "all". Chokidar re-emits the EMFILE as an "error" event, nothing listens for it, and Node throws it as an uncaught exception, killing the process (in a real setup, the Vite dev server running @cloudflare/vite-plugin).
Error: EMFILE: too many open files, watch
at FSWatcher._handle.onchange (node:internal/fs/watchers:269:21)
Emitted 'error' event on FSWatcher instance at:
at FSWatcher._handleError (.../[email protected]/node_modules/miniflare/dist/src/index.js:101804:12)
at NodeFsHandler._boundHandleError (.../miniflare/dist/src/index.js:101032:47)
at .../miniflare/dist/src/index.js:100925:5
at foreach (.../miniflare/dist/src/index.js:100875:5)
at fsWatchBroadcast (.../miniflare/dist/src/index.js:100924:3)
at FSWatcher.<anonymous> (.../miniflare/dist/src/index.js:100965:9)
at FSWatcher.emit (node:events:514:28)
at FSWatcher._handle.onchange (node:internal/fs/watchers:275:12) {
errno: -24,
syscall: 'watch',
code: 'EMFILE',
filename: null
}
Expected
The registry watcher failing should not take the dev server down. Miniflare should handle the watcher's "error" event: log a warning that cross-process service bindings will not pick up registry changes (or fall back to polling, which the registry already uses on Windows and which is cheap for this small directory), and keep running. This is the same class of bug as #13890, fixed for the Wrangler assets watcher in #14027; the dev registry watcher still has no "error" listener.
Actual
Miniflare crashes with the uncaught EMFILE above as soon as DevRegistry#watch attaches its watcher. With the same exhausted FSEvents table but no external service binding (so no registry watch), Miniflare starts, serves a request and disposes cleanly, so the crash comes from the registry watcher alone.
Analysis (hypothesis)
packages/miniflare/src/shared/dev-registry.ts L115-L137 at 41bacf7 (comments trimmed):
const watcher = watch(this.registryPath, {
usePolling: process.platform === "win32",
interval: 100,
ignored: () => !liveness.live,
}).on("all", () => {
this.refresh();
});
Chokidar 4's FSWatcher#_handleError emits "error" for any code other than ENOENT/ENOTDIR (and EPERM/EACCES with ignorePermissionErrors). An EventEmitter with no "error" listener throws. Adding .on("error", ...) that logs through this.log (and, for EMFILE/ENOSPC, closes the native watcher and switches to usePolling: true) should fix it. I read the published [email protected] bundle and main at 41bacf7; I have not patched and rebuilt Miniflare to confirm the fix. watcher.once("ready", ...) in the same function may also need checking, since watch() awaits it after the error.
Reproduction
pnpm install --frozen-lockfile
pnpm run repro:baseline # Miniflare ready, fetch: 200 ok, disposed cleanly
pnpm run repro # uncaught EMFILE from the dev registry watcher
pnpm run repro sets EXHAUST=1, which first starts exhaust-fsevents.js in a separate process. That script opens 1100 FSEvents streams with the fsevents package (one stream per watch() call), filling the machine-wide table; it is killed when the repro exits. Run on macOS only. While it runs, other processes on the machine that start a new FSEvents watch may also fail.
const mf = new Miniflare({
unsafeDevRegistryPath: path.join(scratch, "registry"),
workers: [
{
name: "a",
modules: true,
compatibilityDate: "2026-08-01",
script: "export default { fetch: () => new Response('ok') }",
serviceBindings: { B: { name: "b" } },
},
],
});
await mf.ready;
How it was found
A multi-worker local dev stack (Vite + @cloudflare/vite-plugin 1.70.1 with Wrangler 4.167.0 / Miniflare 4.20260730.0, several workers talking through service bindings and the dev registry) died twice on start on 2026-11-27 on a machine running many file watchers, which had filled the FSEvents table. Vite and the Cloudflare plugin are not needed to reproduce it: plain Miniflare with unsafeDevRegistryPath and one external service binding is enough. The silent FSEvents failure on the fsevents side is filed separately as https://github.com/fsevents/fsevents/issues/414.
- Lingua principale
- TypeScript
- Stelle
- 4.7k
- Fork
- 1.7k
- Merge medio
- 1g 22h
- PR unite (30g)
- 282
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di cloudflare/workers-sdk
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
cloudflare/workers-sdk#17215 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
cloudflare/workers-sdk#17189 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
cloudflare/workers-sdk#17187 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
cloudflare/workers-sdk#17175 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
cloudflare/workers-sdk#17174 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di cloudflare/workers-sdk
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
earendil-works/pi#12615 ·
I maintainer di solito rispondono entro 1 giorno
-
My Caps shows "Shared" on private Caps that were never sharedForse già presa @AksharP5 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
CapSoftware/Cap#4569 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
OHDSI/Data2Evidence#3749 ·
I maintainer di solito rispondono entro 4 giorni
-
PWA: Unique Page TitlesAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Flagsmith/flagsmith-nodejs-client#332 ·
I maintainer di solito rispondono entro 2 giorni