Repository navigation
reduce macos file monitor dropped-event rescan storms - #18508
Conversation
Three changes to how the macOS file monitor copes with fseventsd queue overflow (UserDropped / KernelDropped): - registerMonitor now accepts a best-effort excludedPaths hint, applied on macOS via FSEventStreamSetExclusionPaths. The project monitor passes its always-ignored high-churn directories (.git, .Rproj.user, .quarto, node_modules, renv/library, packrat/lib) so their events are suppressed before delivery instead of after, reducing queue pressure. - dropped-event recovery rescans are debounced: at most one full-tree rescan per interval, with drops arriving inside the interval coalesced into a single deferred trailing rescan (scheduled on the monitor thread's run loop). MustScanSubDirs recursion is skipped while a deferred rescan is pending, since it would perform the same scan. - the FSEvents stream latency is raised from 1s to 2s for more temporal coalescing in fseventsd during sustained churn; NoDefer keeps isolated changes delivered immediately. Addresses #18507
RStudio E2E - all platformsAll tests passed!
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
- retry a failed deferred recovery rescan instead of silently dropping it: batches delivered while the timer was pending skipped their MustScanSubDirs recursion on the promise the rescan would cover them - arm the rescan debounce only from a successful rescan, so a failed attempt no longer suppresses the prompt retry - route MustScanSubDirs-only batches (delivered without the drop flags when fseventsd coalesces hierarchically) through the same debounced rescan, so they cannot trigger unbounded back-to-back full-tree scans
renv's staged installs (the default) write full package payloads into renv/staging before promoting them into the cache; with the cache enabled, renv/library mostly receives one symlink per package. staging is therefore the heavy-churn directory in the renv-install scenario from #18507. it is already unconditionally ignored by fileMonitorFilter (via '/renv/staging/'), so source-level exclusion is semantics-preserving, and the list stays within the FSEvents limit of 8 paths.
CFAbsoluteTimeGetCurrent() is wall-clock time. if the clock steps backward between recovery rescans (ntp correction, vm snapshot restore), 'elapsed' goes negative and the deferred rescan would be scheduled interval + |step| in the future -- with MustScanSubDirs recursion suppressed the whole time on the promise of that rescan. clamp so the delay never exceeds one debounce interval.
Code review findingsFindings from an automated review of this PR, limited to things a user would actually notice. Important
Suggestions
|
gtritchie
left a comment
There was a problem hiding this comment.
LGTM! Some non-blocking feedback.
- MustScanSubDirs without a drop flag returns to the scoped, filter-gated per-path recursive scan (pre-PR behavior), except when flagged on the stream root, where the scoped scan would be a full-tree scan anyway; only drops and root-level coalescing route through the debounced rescan - deferred recovery rescans give up after 3 consecutive failures instead of retrying every 10 seconds forever; a later dropped event re-triggers recovery through the normal path - non-recursive watches (Files pane, prefs) keep the historical 1s FSEvents latency; the 2s bump applies only to recursive watches
|
Thanks -- all three applied in 78b3e86.
|
Addresses #18507.
On macOS, heavy filesystem churn in a monitored project (builds, git operations,
npm ci, ...) can overflow fseventsd's per-client event queue, producing bursts ofFile monitor events were dropped; rescanning ...warnings, each accompanied by a full recursive rescan of the project tree. The bursts are self-amplifying: the recovery rescan runs inline in the FSEvents callback, blocking the run loop long enough for the queue to overflow again.Three changes:
Source-level exclusions.
file_monitor::registerMonitornow accepts a best-effortexcludedPathshint, applied on macOS viaFSEventStreamSetExclusionPaths(Linux/Windows ignore it; inotify never watches filtered directories in the first place, andReadDirectoryChangesWhas no equivalent). The project monitor passes its always-ignored high-churn directories (.git,.Rproj.user,.quarto,node_modules,renv/library,packrat/lib), so their events are suppressed before they transit the queue rather than being discarded client-side after delivery. Callers must still exclude these paths via the filter; the hint only reduces queue pressure.Debounced recovery rescans. Dropped-event rescans now run at most once per 10-second interval. Drops arriving inside the interval coalesce into a single deferred trailing rescan, scheduled via a one-shot
CFRunLoopTimeron the monitor thread's run loop -- the trailing rescan is required for correctness, since dropped changes can postdate what the previous rescan observed. While a deferred rescan is pending,MustScanSubDirsrecursion in per-path processing is also skipped (fseventsd attaches that flag alongside the drop flags, typically on the root path, so honoring it would perform exactly the scan being deferred). Delivered events continue to be processed normally throughout, so prompt updates are unaffected.Longer stream latency. The FSEvents latency is raised from 1s to 2s, doubling fseventsd's temporal coalescing window during sustained churn. Streams use
kFSEventStreamCreateFlagNoDefer, so the first event after an idle period is still delivered immediately; only follow-on events batch.The new
FileMonitorTest.RecursiveExcludedPathSuppressesEventstest covers the exclusion plumbing end-to-end (and empirically confirms fseventsd excludes events whose path equals the excluded directory, which is the.gitcase under directory-granularity streams). The debounce path requires genuine queue overflow and so is not deterministically unit-testable; verification there is by inspection plus observing warning cadence in real sessions.All
--scope coretests pass locally (484 passed, 8 environment-dependent skips).