#885·fff

[Bug]: overlapping pickers in one process each open their own inotify instance, multiplying watches against the per-uid limit

Author: connor-gradyCreated Sep 23, 2026Updated Sep 23, 2026

Which fff frontend?

Bun SDK (@ff-labs/fff-bun 0.9.4) and the core crate.

Description

On Linux each BackgroundWatcher creates its own debouncer, and therefore its own inotify instance. create_debouncer in crates/fff-core/src/watcher/background_watcher.rs calls new_debouncer_opt once per BackgroundWatcher::new, and the file contains no static, OnceLock, OnceCell or lazy_static, so nothing is shared process-wide. Many pickers in one process has been a supported configuration since #235, and embedders do create several. When two pickers cover overlapping paths, every shared directory is watched once per picker.

That duplication is not free, because of how the kernel accounts watches. inotify(7) describes the watch list as belonging to an inotify instance, and inotify_add_watch(2) "either creates a new watch item, or modifies an existing watch", so a directory reached twice within one instance costs one watch. But the same page describes max_user_watches as "an upper limit on the number of watches that can be created per real user ID". There is no deduplication across instances, so M pickers over the same N directories cost M×N of a budget shared with every other process the user owns. max_user_instances is per-uid as well.

Measured on five live embedder sessions. engines counts fff-watcher-own threads, and each engine had exactly one matching notify-rs inoti thread and one inotify file descriptor. watches sums inotify wd: lines across /proc/<pid>/fdinfo/*, and distinct_dirs counts unique inodes in those same lines. Sessions A through C were opened on one repository, D and E on another.

session  engines  watches  distinct_dirs  ratio
A        2        227      227            1.00
B        2        436      227            1.92
C        2        436      227            1.92
D        3        253       92            2.75
E        2        170       91            1.87

In session D all three engines watch the same base path, and two of them hold byte-identical inode sets:

fd30 (84) vs fd32 (85): shared=83 only_a=1 only_b=2
fd30 (84) vs fd35 (84): shared=84 only_a=0 only_b=0
fd32 (85) vs fd35 (84): shared=83 only_a=2 only_b=1
union of all: 86   sum of sizes: 253

On a large checkout of roughly 300k directories this multiplier saturated the limit at 522,895 of 524,288 watches, leaving 81 for the rest of the machine, and an unrelated dev server then died with ENOSPC: System limit for number of file watchers reached. The per-tree cost is irreducible and I am not asking for it to shrink: notify's RecursiveMode::Recursive is emulated one watch per directory, and the O(1) whole-tree fanotify marks FAN_MARK_MOUNT and FAN_MARK_FILESYSTEM both require CAP_SYS_ADMIN per fanotify_mark(2). Deduplication is the only headroom available, and it costs nothing in coverage.

Two changes would close it. A process-global watcher backend, refcounted per watched path and fanning events out to subscribed pickers, so overlapping pickers pay once. @parcel/watcher does exactly this: Backend::getShared in src/Backend.cc:71 resolves against a process-static map declared at :24. Separately, the per-directory registration loop currently has MAX_CONSECUTIVE_WATCH_FAILURES = 16 as its only backstop and no budget, so a single picker can consume the entire per-uid allowance before it notices; deriving a ceiling from max_user_watches would make exhaustion a degradation rather than a machine-wide outage.

This is in-process and orthogonal to #850, which proposes sharing indexes across separate fff-mcp processes via a daemon.