rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

vfs-notify drops notify's rescan event on Linux inotify queue overflow, leaving server-side file state stale

Open kureist opened this issue 3 weeks ago • 3 comments

rust-analyzer version: rust-analyzer 0.3.3113-standalone (2026-11-09)

rustc version: rustc 1.99.1 (58cf8f9c3 2026-10-13)

editor or extension: Minimal custom LSP client script on Linux

relevant settings:

{
  "rust-analyzer.files.watcher": "server"
}

(Only affects server-side watching; the default "client" mode is not involved.)

repository link: rust-analyzer-server-watcher-overflow

code snippet to reproduce:

// src/lib.rs
mod value;

pub fn get() -> u32 {
    value::VALUE
}
// src/value.rs
pub const VALUE: u32 = 1111;

Steps to reproduce / Observed behavior

On Linux 7.3.3 (Fedora 44) with the default inotify queue limit (fs.inotify.max_queued_events = 16384)::

  1. Start rust-analyzer with files.watcher = "server" on a crate containing the files above.
  2. Open only src/lib.rs and confirm hover on value::VALUE shows 1111.
  3. Update src/value.rs on disk to pub const VALUE: u32 = 2222; and confirm hover follows and shows 2222 (control: a plain edit is picked up).
  4. Pause the rust-analyzer process (SIGSTOP).
  5. Create 20480 new files in src/ (exceeding the 16384 queue limit), then update src/value.rs on disk to pub const VALUE: u32 = 3333;.
  6. Resume the rust-analyzer process (SIGCONT).

Result:

  • Hover on value::VALUE in src/lib.rs still shows 2222.
  • Creating or touching another file in src/ afterwards does not recover the stale state.
  • Restarting rust-analyzer shows 3333.
  • Control: repeating the exact same steps with 200 new files instead of 20480 updates hover to 3333 as expected. Both cases (20480 and 200) were run 3 times with identical results.

Cause

When the kernel inotify queue overflows, it drops further events and queues an overflow record. The notify crate converts that record into an event with EventKind::Other and the rescan flag (event.need_rescan() == true).

In crates/vfs-notify/src/lib.rs (master at 8ba7bef, linked below), vfs-notify only acts on Create, Modify, Remove, and Access(Open), and need_rescan does not appear anywhere in the file. As a result, the overflow notification is silently ignored and files whose events were dropped retain stale contents.

https://github.com/rust-lang/rust-analyzer/blob/8ba7bef996a21ee8157d13f141b0525b092a9872/crates/vfs-notify/src/lib.rs#L201-L204

Possible fix

When event.need_rescan() is true, reload the watched entries as done on start-up (and report any changed files).

Scope / Not checked

  • Editor-side watchers (files.watcher = "client", the default).
  • macOS and Windows (though notify sets the same rescan flag when FSEvents drops events on macOS).
  • How frequently inotify queue overflows occur in everyday editing workflows.

Assisted by Anthropic Claude Fable 5.2

kureist avatar Nov 12 '26 12:11 kureist

Assisted by Anthropic Claude Fable 5.2

Did you read the AI policy?

ChayimFriedman2 avatar Nov 12 '26 12:11 ChayimFriedman2

Yes I do, and this comment is not generated by AI. I wrote assist by Claude Fable 5.2 because during the process of finding the bug, I used the AI model.

kureist avatar Nov 12 '26 12:11 kureist

Sorry but this is not a bug. If you have too many watched files you need to increase the limit. Furthermore I highly doubt you really have a workspace with 20,000 files, so this seems like a highly artificial report which is not always welcome.

I might accept a fix if either:

  • We'll get report of people actually hitting this regularly in the wild (very unlikely), or
  • The diff is no more than a few lines.

ChayimFriedman2 avatar Nov 12 '26 12:11 ChayimFriedman2