Repository navigation
Conversation
When FSEvents reports dropped events (MustScanSubDirs, KernelDropped or UserDropped), the macOS folder watcher enumerated the entire sync folder on the main thread and passed every entry through the per-path change handling. With a large tree this blocks the main thread for minutes, so more events are dropped meanwhile and the next enumeration starts right after: the client stays at 100 % CPU and the UI does not respond. Emit lostChanges() instead, as the Windows watcher does on buffer overflow. The folder now reacts to lostChanges() by scheduling a sync with full local discovery, which runs in the sync engine and does not descend into excluded directories. Closes nextcloud#10931 Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: JMoVS <git@justinscholz.de>
|
Tested this PR on macOS and compared it with the stock client and with the same PR plus a second change for the per-path cost (tracked in #11353). Summary: the PR removes the full-tree enumeration as intended, and the second change removes most of what is left. Setup
S1: 200,000 files moved into an excluded directory
S2: 300,000 files created in an excluded directory
Reading the numbers
Limits
|
|
We hit exactly the freeze this PR addresses on a real account, and could not test the build — so this is a reproduction report rather than a review. Client 35.0.3, macOS 26.5.2 (Apple silicon), server 35.0.2. One folder pair, 233 499 items to compare, ~368 GB account, selective sync excluding ~267 GB of server-only folders. Symptom: the main thread sat at 89–95 % CPU for more than 15 minutes while the byte counters in Activity Monitor stayed flat and sync progress stalled after 6 files. 1 790 of 2 331 samples in Could not test the fix: every workflow on this branch is Workaround that worked for us: the same engine headless — How the exclusion actually had to be passed, since we lost time to this: Measured on the same tree: Assisted by DeepSeek:deepseek-v4.1-flash-1017 |
Summary
On macOS, the client can freeze at 100 % CPU on the main thread when a large sync folder sees heavy file churn (for example dependency or build trees, or git worktrees, inside the sync folder). Closes #10931.
When FSEvents reports dropped events (
kFSEventStreamEventFlagMustScanSubDirs,KernelDroppedorUserDropped),FolderWatcherPrivate::notifyAll()enumerated the whole sync folder with aQDirIteratoron the main thread and passed every entry throughFolderWatcher::changeDetected()→Folder::slotWatchedPathChanged()→Folder::pathIsIgnored(). Excluded directories are enumerated too, because exclusion is only checked per path afterwards. While this runs, the FSEvents queue is not drained, so more events are dropped and the next enumeration starts immediately afterwards.Change
folderwatcher_mac.cpp: on dropped events, emitlostChanges()instead of enumerating the folder. This matches the Windows watcher's behaviour onERROR_NOTIFY_ENUM_DIR.folder.cpp:lostChanges()is now connected to a newFolder::slotWatcherLostChanges(), which forces a full local discovery for the next sync (as before) and schedules that sync. PreviouslylostChanges()only invalidated the full-discovery timer and relied on a path change to schedule the sync.FolderWatcher::testMacSimulateDroppedEvents(): test hook, followingtestLinuxWatchCount(). FSEvents ignores changes made by the client's own process, so the dropped-events path cannot be triggered from a test otherwise.The same
notifyAll()change was first proposed by @cotchon in #10931 (comment). There,notifyAll()also reports the sync folder root throughchangeDetected()so that a sync gets scheduled. This PR schedules the sync fromFolderinstead, because reporting the root trips an assert in Debug builds (see Manual verification).Tests
TestFolderWatcher::testDroppedEventsReportLostChangesInsteadOfPaths(macOS only): checks that dropped events emitlostChanges()once and report no paths. It fails onmaster(lostChangesemitted 0 times) and passes with this change.TestFolderMan::testWatcherLostChangesSchedulesSync: checks thatFolder::slotWatcherLostChanges()puts the folder into the sync schedule queue. It fails when thescheduleThisFolderSoon()call is removed.FolderWatcherTest,FolderWatcherChangeDetectionTest,FolderManTest,LocalDiscoveryTest,SelectiveSyncTest,SyncMoveTest,SyncDeleteTest,SyncConflictTest,SyncConflictsModelTestall pass.ActivityListModelTest::testAddError_manyIgnoredFiles_benchmarkfailed once when run in parallel with other suites (ctest -j8) and passed twice when run alone. This change does not touch that code.Manual verification
Debug build of this branch, signed with a personal team, classic sync (no File Provider), syncing a test folder:
Results:
samplestacks.For comparison, a stock 35.0.2 client on a 940k-entry sync folder with similar churn repeated the full enumeration every ~2.5 minutes until it was restarted. These numbers are from that client's own logs and were not reproduced with the test folder above.
An earlier revision of this change also reported the sync folder root as a changed path. In a Debug build this triggers
Q_ASSERT(!systemPath.endsWith('/'))inSocketApi::broadcastStatusPushMessage(). That is why the final change reports no path and letsFolderschedule the sync.Notes / follow-ups (not in this PR)
FolderWatcher::changeDetected()andFolder::slotWatchedPathChanged()still runs on the main thread. During each 20,000-file burst it kept the main thread busy for a few seconds, which is ordinary event processing and not the loop fixed here. This per-path cost in excluded trees is tracked in macOS: excluded paths still cost a full pass through the watcher per event, andaddCoalescedPaths()walks excluded directories #11353.MustScanSubDirsnames a subtree. This change escalates it to a full local discovery of the sync folder, which is the conservative choice. Limiting it to the subtree viaschedulePathForLocalDiscovery()is a possible refinement.lostChanges()on overflow for Linux and Windows) and fix(folderwatcher): do not walk or list the content of excluded folders #11372 (excluded folders on Linux). Neither touchesfolderwatcher_mac.cpp. fix(folderwatcher): do not walk or list the content of excluded folders #11372 also adds tests totest/testfolderwatcher.cpp; a test merge shows a trivial conflict there only.folderwatcher_mac.cppon lines this PR does not change (modernize-use-auto×2,modernize-use-nullptr,modernize-use-nodiscard). They are left out to keep this PR focused, and none are on changed lines.AI disclosure
This change was developed with Claude Code (claude-opus-5-5): analysis of the stack samples, the implementation, the tests and the test-folder reproduction scripts. I reviewed the diff and ran the tests and the manual verification described above.
🤖 Generated with Claude Code