desktop icon indicating copy to clipboard operation
desktop copied to clipboard

macOS File Provider 34.0.4: repeated enumeration and rapidly oscillating sync status with ignored items

Open swwwamo opened this issue 2 months ago • 1 comments

macOS File Provider repeatedly refreshes directories and oscillates sync status

Environment

  • Nextcloud macOS client user agent: mirall/34.0.4, macos-25.6.0, arm64.
  • File Provider / virtual files enabled (Finder Locations, cloud-only placeholders).
  • Nextcloud server 34.0.3 (internal version 34.0.3.2), self-hosted on Umbrel; maintenance=false, needsDbUpgrade=false.
  • Observed 18 September 2026. Client log times below are local time.

Symptoms

The client rapidly alternates between synced, syncing, and a missing-files status. The server processes sustained WebDAV directory requests, causing noticeable CPU use and fan noise.

Pausing/quitting the Mac client reduced server CPU from approximately 32% to 2–6% in short samples. CPU temperature later fell to 65°C. This associates the workload with sync activity; it does not identify the underlying defect.

Evidence and timeline

  1. An earlier session contained 823 failed content-download log entries, including repeated HTTP 404 responses for AppleDouble-style ._ files in an old presentation folder. The final recorded 404 in that session was at 14:41:24.
  2. Later server samples showed directory PROPFIND responses with HTTP 207 and occasional successful GET responses with HTTP 200, without the earlier 404 burst. Response bodies were not inspected; HTTP 207 alone does not establish success of every property.
  3. File Provider logged thousands of ignored-file events: local removal/untracking with an explicit statement of no remote effect, interspersed with transitions to dataless state. Counts are log events, not necessarily unique files. This does not by itself prove an endless cycle for each item.
  4. A separate unsupported-symbolic-link error identified a Python executable link in a virtual environment. The user subsequently removed the virtual environment, but refresh activity persisted.
  5. A later ~75-second session contained 37 enumerator setups for the excluded environment and 37 for its bin directory, despite saved folder and descendant exclusion patterns.
  6. After removal of that environment was verified locally, enumerator setup events continued for the account root, a notes folder, and a child folder, sometimes several times within a second. Repeated enumerator creation is an observed symptom, not proof that each event caused a full remote scan.
  7. The user reports the problem also occurs on a second Mac. A subsequent test with that Mac paused and only Nextcloud open on the tested Mac still showed the visible loop. This last test is user-reported; its logs have not yet been separately collected.

Sanitized representative log events

15:16:31 Item: Cannot create item __fp/fs/fileID(<redacted>), symbolic links not supported.
15:37:47.486 Enumerator: Set up enumerator. /remote.php/dav/files/<user>/<notes>
15:37:47.488 Enumerator: Set up enumerator. /remote.php/dav/files/<user>/<notes>/<child>
15:37:47.488 Enumerator: Set up enumerator. /remote.php/dav/files/<user>
15:37:47.893 MaterializedEnumerationObserver: Updating item state to dataless. <ignored ._ file>
15:37:47.909 Enumerator: Set up enumerator. /remote.php/dav/files/<user>
15:37:47.911 Enumerator: Set up enumerator. /remote.php/dav/files/<user>/<notes>
15:37:47.912 Enumerator: Set up enumerator. /remote.php/dav/files/<user>/<notes>/<child>
15:37:47.918 Item: File is in the ignore list. Will delete from local database with no remote effect.

Tests already tried

  • Pause/resume and quit/reopen the desktop client.
  • Verify ._* exclusion exists; logs confirm ignored-file handling is active.
  • Add a virtual-environment folder exclusion and a correctly rooted descendant pattern.
  • Remove the identified replaceable Python environment; activity continues elsewhere.
  • Pause the other Mac and close Finder windows/Obsidian on the tested Mac; user reports the loop persists.

No File Provider database reset, account removal/re-add, or bulk metadata cleanup has been performed during this investigation. These are deliberately avoided because some files are cloud-only and unsynced local data has not been inventoried.

Expected behavior

After reconciling available changes and exclusions, the client should settle into a stable status. If a specific item prevents this, its error should remain inspectable rather than disappear immediately as status changes.

Questions for maintainers

  1. Can ignored-item untracking and dataless transitions repeatedly invalidate enumeration or account status in this release?
  2. What diagnostics distinguish a finite reconciliation backlog from a repeating File Provider state loop?
  3. Is there a known fix in a released version, and what non-destructive recovery procedure preserves cloud-only and unsynced files?
  4. Which targeted logs are needed? Raw logs contain private filenames and should not be posted publicly without sanitizing.

Related report: https://github.com/nextcloud/desktop/issues/9747 (virtual-file exclusion behavior; not confirmed to be the same bug).

Reproduction limitations and privacy

This was observed with an existing sync domain containing cloud-only placeholders and ignored metadata files; no minimal clean-account reproducer is available yet. The second Mac's exact version has not been independently verified. No claim is made that the related issue or the unsupported symbolic link is the root cause.

Log excerpts are reformatted and sanitized. Account identifiers, hostnames, personal paths, file IDs, and original filenames are omitted. No raw logs, databases, credentials, or configuration files are attached.

swwwamo avatar Sep 18 '26 13:09 swwwamo

Seeing the same thing on 34.0.4. I caught an episode in progress and profiled it, and I have a full log of one complete cycle from onset to self-resolution — including what looks like a self-sustaining signal loop. Posting in case it's useful.

Environment

  • Nextcloud Desktop 34.0.4, macOS 27.0 (26A428), ARM64
  • Domain Realm: 246 MB (257,589,248 bytes)
  • Large working set: the account holds backup trees (a Linux $HOME including node_modules, a web server /usr, a borg repo, per-conversation chat-export directories) — a very deep, wide tree of tiny files

The episode is self-limiting, but expensive

It is not a permanent loop. One complete cycle, from the domain's JSONL log:

Onset 21:39:18
End 22:03:33
Duration 24 min 15 s
Set up enumerator. events 2,898 over 1,564 distinct directories
CPU consumed ~29 min 50 s (ā‰ˆ123%, i.e. ~1.2 cores sustained)
Preceding 23.9 h 7 min 10 s total (~0.5% avg)
Following 13.3 h 0 enumerator setups

So: near-idle, then ~1.2 cores for 24 minutes, then clean convergence and quiet. That matches the "oscillating then settling" behaviour in this issue.

41% of the enumerations were near-empty — Did enumerate 0 items 254Ɨ, 1 item 932Ɨ out of 2,876. Mostly per-directory setup/teardown overhead.

The signal rate goes up 250Ɨ during the episode

This is the part I think matters most. Measuring the interval between consecutive Received file ID changes for locally known metadata. Signalling enumerator. messages:

Phase Count Median gap
Before onset 144 505 s
During episode 482 2.0 s
After (13.3 h) 100 481 s

The baseline is ~8 minutes, and it is identical before and after. During the episode it collapses to 2 seconds and stays there for the full 24 minutes.

Nothing external changed — no account reconfiguration, no ignore-list update, no user activity in that window (the nearest Ignore list updated. events are hours away on either side). The signal storm begins and ends with the enumeration.

Since the message is specifically about locally known metadata, my reading is a feedback loop: enumeration writes item metadata → those local writes raise file-ID-change notifications → the notification signals the enumerator → it enumerates and writes again. It would then terminate once a pass finally produces no metadata changes, which is consistent with the abrupt stop at 22:03 and the 13.3 quiet hours afterwards despite 100 further signals at baseline rate. I haven't proven that causal direction from the outside, but the 250Ɨ correlation is tight and the loop closes on its own.


Why each pass is so expensive

Captured with sample(1) against the live process at ~90% CPU during the episode.

1. Item.childItemCount runs an unindexed full table scan, once per enumerated item

-[FPXItemsObserver didEnumerateItems:]
  -[FPXObserver updateForProviderItem:]
    -[FPXDomainContext itemFromVendorItem:]
      -[FPItem initWithVendorItem:provider:domain:...]
        Item.childItemCount.getter                       (FileProviderExt)
          RealmCollectionImpl.count.getter               (RealmSwift)
            -[RLMResults count]
              realm::Results::size()
                realm::Query::do_count(unsigned long)
                  realm::ClusterTree::traverse(...)      <-- full scan
                    realm::ClusterNodeInner::traverse(...)
                      realm::Query::aggregate_internal(...)
                        realm::ParentNode::find_all_local(...)
                          realm::OrNode::find_first_local(...)

OrNode implies a compound OR predicate, which Realm can't serve from an index — so this is a genuine table walk, run once per item handed to the framework. Enumerating N items is O(N²). On a 246 MB database this dominates.

Item.contentType.getter adds an uncached LaunchServices lookup per item (_UTEnumerateTypesForTag → _LSDatabaseEnumeratingBindingMap → _CSArrayEnumerateAllValues).

2. One Realm write transaction per item, each forcing an msync

FilesDatabaseManager.addItemMetadataPreservingLocalState(_:preserveVisitedDirectory:)
  FilesDatabaseManager.addItemMetadata(_:)
    Realm.write<A>(withoutNotifying:_:)
      Realm.commitWrite(withoutNotifying:)
        -[RLMRealm commitWriteTransactionWithoutNotifying:error:]
          realm::Realm::commit_transaction()
            realm::Transaction::commit_and_continue_as_read(bool)
              realm::DB::do_commit(...)
                realm::DB::low_level_commit(...)
                  realm::WriteWindowMgr::sync_all_mappings()
                    realm::util::msync(...)
                      __msync                            <-- 82/179 samples in commit
                  realm::GroupWriter::write_group()
                    realm::GroupWriter::read_in_freelist()
                    realm::GroupWriter::recreate_freelist(unsigned long)

About 46% of commit time is __msync — a forced disk flush per item. That's the sustained-disk-write and battery cost, separate from the CPU.

The rest is freelist maintenance. Top symbols across the sample:

488  realm::GroupWriter::FreeSpaceEntry
279  realm::GroupWriter::recreate_freelist
161  realm::_impl::ArrayWriterBase
139  realm::Array::do_write_deep
 71  realm::DB::low_level_commit
 60  realm::StringIndex::leaf_insert

The file is rewritten in place without growing (stable at 257,589,248 bytes across writes) — heavily fragmented, so every per-item commit rebuilds a large freelist, with no compaction step to recover. This is the likely mechanism behind the older "gets bad once the database is large" reports.

If the feedback-loop reading above is right, these two costs are what turn a benign re-signal into 24 minutes of pinned CPU: the loop sets the iteration count, and the O(N²) enumeration plus per-item msync set the price of each iteration.

3. Realm open/close churn

sample observed 97 threads across a 10-second window with only 10 alive at the end — ~87 Realm notification listener threads (realm::_impl::ExternalCommitHelper::listen()) created and destroyed in 10 s, suggesting Realm instances are opened and torn down per unit of work rather than reused.


Possible directions

  1. Break the signal loop — suppress or coalesce file-ID-change notifications arising from the enumerator's own metadata writes. This caps iterations regardless of the per-pass cost.
  2. Index or restructure the childItemCount query — the OR predicate defeats indexing; splitting it, or denormalising a child count onto the parent row, removes the O(N²) term.
  3. Batch metadata writes per enumeration page instead of per item — collapses both the msync count and the freelist rebuilds by orders of magnitude.
  4. Compact the Realm periodically (shouldCompactOnLaunch / explicit writeCopy).
  5. Cache contentType rather than hitting LaunchServices per item.

Notes

#7326 was closed on the basis that the 3.17.0 architectural work would eliminate large-database unresponsiveness. The symptom is clearly much reduced — this now self-resolves in 24 minutes rather than persisting — but both hot paths above are still present in the 34.0.4 binary. Happy to open a separate issue for the Realm performance side if it's better tracked apart from the enumeration loop.

This may also be relevant to #10106 / #9046: the per-item msync and the freelist rebuild cost are consequences of how Realm is driven here, and both would be straightforward to avoid under GRDB.

Medformatik avatar Sep 22 '26 09:09 Medformatik