Skip to content

Deleted/ignored scan does a SQLite virtual-mtime lookup per file, so large folders never pull #10909

Closed as not planned

Description

@jhf

What happened?

On a large send/receive folder, payload pulls starve even though a needed file is available from a connected peer and there are no pull errors. The folder spends a long time in scanning. A stack sample during that state is not in the GC: it is in the deleted/ignored pass, doing a SQLite virtual-mtime lookup for every local path.

scanSubdirsDeletedAndIgnored calls osutil.IsDeleted on each local index entry. That only needs existence, type, and symlink-parent checks. It was going through mtimeFS.Lstat, which loads a row from the mtimes table even though IsDeleted never uses the mtime.

This is not #10868. That issue is orphan-block GC hitting the time limit on a huge blocks table. We also log that GC line on this folder (~2.5M block rows, 25 chunks, a few chunks per 5–13 minutes). During the pull hang there were zero GC-interrupt lines and a stale WAL. Different function, same “large SQLite folder” neighbourhood.

Syncthing version

v2.1.5 (stock hang), reproduced with a patched v2.1.6-dev build

Platform & operating system

macOS darwin-arm64, folder home ≈ 2.2M files / 370k dirs, one Linux peer

Relevant log output

Hung process (sample, 10s, non-destructive):

folder.Serve
  scanTimerFired
    scanSubdirs
      scanSubdirsDeletedAndIgnored
        osutil.IsDeleted
          mtimeFS.load / sqlite GetMtime

A second thread was in sqlite3_step / sqlite3BtreeTableMoveto the whole sample. REST: state=scanning, needFiles=2, peer connected, CPU ~1% after 66 minutes. No GC was interrupted lines during that hang.

After skipping the virtual-mtime lookup on existence checks (fs.LstatExists, used by IsDeleted and TraversesSymlink; case-conflict wrapping kept):

15:32:11  scanning (~80-100% CPU)
15:38:30  Completed initial scan (6.3 min, 1472 changes)
15:38:33  Synced file roundtrip-121708.txt
then idle, needFiles=0, stayed idle

Same folder, later run of the same patch: scan 19:16:44 → completed 19:25:24 → idle, needFiles=0.

Unit tests: TestLstatExistsSkipsMtimeDatabase, TestIsDeletedSkipsMtimeDatabase.

Branch on current main (happy to open a PR if wanted; CONTRIBUTING asks new contributors not to send unsolicited PRs):

https://github.com/jhf/syncthing/tree/fix/fs-skip-mtime-on-exists

Related: #10868 (GC time limit on blocks, not this scan path)

Activity

  1. calmh commented on Oct 5, 2026

    @calmh
    Member

    Scans and pulls are interleaved. Is this just a longwinded way of saying "scans take longer than I expect"?

  2. jhf commented on Oct 5, 2026

    @jhf
    Author

    Not just a slow scan. Pulls never ran until that pass finished.

    Stock v2.1.5 on this folder (pid 73232): launched 13:23:32, still in scanSubdirsDeletedAndIgnored → IsDeleted → SQLite GetMtime at 15:07:49 (1 h 44 min). REST stayed scanning, needFiles=2, peer connected, no payload. We did not wait for it to complete. (Completed initial scan at 13:41 / 14:01 in that window were folder restarts from a watcher A/B; REST never left scanning / needFiles=2.)

    After skipping the virtual-mtime lookup on existence checks, same folder: 15:32:11 scanning → 15:38:30 completed (6.3 min) → pulled the waiting file at 15:38:33, idle needFiles=0. Two later runs completed in 8.7 and 9.0 min.

    On the interleave: yes, scan and pull share the folder Serve loop (lib/model/folder.go). Pull is scheduled on a 1-buffered pullScheduled, and pull() itself returns immediately until initialScanFinished is closed:

    select {
    case <-f.initialScanFinished:
    default:
        // Once the initial scan finished, a pull will be scheduled
        return true, nil
    }

    The first scan is scanTimer fired at 0 → scanTimerFired → scanSubdirs (walk, then scanSubdirsDeletedAndIgnored on every local name) on that same goroutine. initialScanFinished is only closed after scanSubdirs returns. While that call is in GetMtime, the select is not running, so a queued pull is not taken, and even if pull() were entered it would no-op.

    So the interleave is real after the initial scan returns. During this pass it never got a turn. IsDeleted does not need virtual mtime; consulting it on every local name is what kept the serve loop in scanSubdirs.

  3. jhf commented on Oct 5, 2026

    @jhf
    Author

    Scans and pulls are interleaved. Is this just a longwinded way of saying "scans take longer than I expect"?

    So yes, but so much longer it wasn't usable.
    Running locally with the fixed binary now.

  4. jhf commented on Oct 15, 2026

    @jhf
    Author

    @calmh I will just mention that since I use synching for my entire HOME directory, I can't use it without this and several other fixes, so I must then keep a forked version with this and other patches to make it run.

  5. added 2 commits that reference this issue on Oct 24, 2026
  6. added a commit that references this issue on Nov 4, 2026
  7. added a commit that references this issue on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions