fs: Retry watch registrations skipped during the native watch-limit cooldown (#60662)

GlobalWatcher::add returns Ok(None) while the native watch-limit
cooldown is active, and FsWatcher::add_existing_path treated that as
success: the path was never watched, with no retry and no error. A
long-lived watch (like a repository's git directory) that happened to
register during a cooldown window silently never received events.

Route the skipped registration through the existing pending-path
machinery, which already polls until registration succeeds and emits a
rescan event for the path so that changes missed in the interim are
picked up.

---

Release Notes:

- N/A or Added/Fixed/Improved ...
This commit is contained in:
Lukas Wirth 2026-07-09 14:39:43 +02:00 committed by GitHub
parent 8230cb16d1
commit e2d41c477c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -56,13 +56,22 @@ impl FsWatcher {
log::trace!("path to watch is already watched: {path:?}");
return Ok(());
}
if let Some(registration) = register_existing_path(
path,
match register_existing_path(
path.clone(),
case_insensitive,
self.tx.clone(),
self.pending_path_events.clone(),
)? {
self.registrations.lock().insert(key, registration);
Some(registration) => {
self.registrations.lock().insert(key, registration);
}
None => {
// Registration was skipped (e.g. the native watch-limit cooldown
// is active). Retry in the background rather than silently leaving
// the path unwatched forever.
log::warn!("watch registration for {path:?} was skipped; retrying in background");
self.add_pending_path(path);
}
}
Ok(())
}