Unverified Commit 1dd198b6 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

turbo-tasks-fs: Don't print NotFound watcher errors (#99794)

### What?

Stop the Turbopack disk watcher from printing `watch error … NotFound`
for paths that vanish while notify is scanning them, and send the
remaining watcher errors to stderr instead of stdout.

### Why?

In polling mode, notify's `PollWatcher` walks the tree with walkdir.
When a directory is deleted between being listed and being opened or
stat'ed, notify reports an `Io` error with `NotFound`. Deleting a large
tree (`rm -rf`, a package install) produces a burst of these. A
filesystem fuzzer saw about 4000 in two minutes. Each one was printed
with `println!`, so a library was spamming the user's stdout.

These errors don't signal a correctness problem. The watcher already
invalidates the reported path recursively, and the next scan reports the
removal anyway. The fuzzer runs had no missed invalidations.

### How?

- A small private classifier recognizes notify errors of kind `Io`
wrapping `std::io::ErrorKind::NotFound`. It matches on the structured
error kinds, not on message text.
- The watcher thread skips the print for those errors. Batch
invalidation and batch-delay scheduling still run for every error, so
invalidation behavior doesn't change.
- Other notify error kinds, including `PathNotFound`, are still
reported, now on stderr.

### Verification

- `cargo test -p turbo-tasks-fs --lib watcher::tests`: 19 passed,
covering native and polling watchers in both recursive and non-recursive
modes
- `cargo clippy -p turbo-tasks-fs --tests -- -D warnings`
- Not run: a deletion stress test reproducing the race (the fuzzer
finding above).

<!-- NEXT_JS_LLM -->


<!-- fleet 89bd34bb-fe6a-4ea4-abcc-abb97db76087 -->

---------
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent a32ddfdf
......@@ -701,7 +701,12 @@ impl DiskWatcher {
}
// Error raised by notify watcher itself
Ok(Err(notify::Error { kind, paths })) => {
println!("watch error ({paths:?}): {kind:?} ");
// A path removed while the watcher was scanning it is expected (e.g.
// `PollWatcher` walking a tree that is being deleted), so don't report
// it. The invalidation below still covers it.
if !is_not_found_error(&kind) {
eprintln!("watch error ({paths:?}): {kind:?} ");
}
batch.add_error(paths, fs.root_path());
schedule.extend(config.batch_delay);
......@@ -1195,6 +1200,12 @@ impl InvalidationReasonKind for InvalidateRescanKind {
}
}
/// Whether a [`notify::Error`] was caused by a path that no longer exists, e.g. a directory
/// removed between being listed and being read by [`PollWatcher`].
fn is_not_found_error(kind: &notify::ErrorKind) -> bool {
matches!(kind, notify::ErrorKind::Io(err) if err.kind() == std::io::ErrorKind::NotFound)
}
#[cfg(test)]
mod tests {
use std::{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment