You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(runtime/ops): unwatch shared RecommendedWatcher on FsWatcher close (#34467)
## Summary
Closing a `Deno.FsWatcher` left its underlying notify watch behind.
Since #26200
the runtime shares one `RecommendedWatcher` across all
`Deno.watchFs(...)` calls
in an OpState, but the close path never told that watcher to unwatch
anything.
On Windows each `Watcher::watch(path, ...)` call registers a separate
`ReadDirectoryChangesW` operation, so opening and closing watchers
repeatedly
on the same path leaks watches whose callbacks all keep firing — the
next
`Deno.watchFs(...)` for that path then sees every event N times.
This PR reference-counts per `(path, recursive_mode)` in the shared
`WatcherInner`: `watch` is only called when the count transitions 0→1,
and
`unwatch` when it transitions 1→0. Each `FsEventsResource` carries an
`Arc<WatcherInner>` plus a unique `id` and the list of `(path, mode)`
pairs it
registered, so its `Drop` impl can both remove its `WatchSender` from
the
shared dispatch list and decrement the per-path refcounts.
The duplicate-event symptom only reproduces on Windows because Linux's
inotify
backend deduplicates `inotify_add_watch` on the same path and macOS's
FSEvents
does the same — the existing leaked-`WatchSender` and leaked-watch state
were
silent there, but they're still incorrect.
Fixes#27742.
Closes denoland/orchid#261
## Test plan
- [x] Added `watchFsCloseAndRecreateNoDuplicates` to
`tests/unit/fs_events_test.ts`
mirroring the reproducer in #27742 (open/close 3 watchers, then a 4th
observes a single fs change). Asserts each `(kind, path)` is reported
at most twice (a real `create` plus an optional `modify`). On the buggy
build this would be N copies on Windows.
- [x] `cargo build --bin deno`
- [x] `cargo clippy -p deno_runtime`
- [x] All 12 tests in `tests/unit/fs_events_test.ts` pass with the
patched
binary on Linux.
- [ ] CI to validate Windows.
Co-authored-by: divybot <divybot@users.noreply.github.com>
Co-authored-by: Divy Srivastava <me@littledivy.com>
0 commit comments