Skip to content

Windows: STATUS_ACCESS_VIOLATION crash in SQLite cgo during folderSummaryService.calculateSummaries #10592

Closed

Description

@pulpier

What happened?

Summary

Syncthing crashes repeatedly on Windows with a STATUS_ACCESS_VIOLATION (0xc0000005) exception inside the SQLite cgo bindings. The crash always occurs in the same call chain: folderSummaryService.calculateSummaries → folderDB.CountNeed → folderDB.needSizeRemote → SQLiteRows.nextSyncLocked → _Cfunc__sqlite3_step_internal.

The fault address varies across crashes (e.g. 0x0, 0x7ff6fdb1d478, other addresses), which is consistent with a race condition on a prepared statement or database handle in the cgo/SQLite layer.

Expected behavior

Syncthing runs without crashing while computing folder sync summaries in the background.

Steps to reproduce

  1. Run Syncthing v2.0.16-rc.1 on Windows 11
  2. Have at least one folder configured for sync
  3. Syncthing crashes within seconds to minutes, always in the same stack

Notes

  • Deleting the entire index-v2/ database directory and forcing a full rescan did not fix the crash — it reappears immediately after rescan
  • The crash pre-dates v2.0.16-rc.1; it appears to have existed for some time
  • This is a cgo crash ("signal arrived during external code execution"), so it originates in C code (go-sqlite3 v1.14.34), not in Go code
  • No existing GitHub issue was found for this specific stack trace

Syncthing version

v2.0.16-rc.1 (go1.25.7, windows-amd64)

Platform & operating system

Windows 11 (windows/amd64)

Browser version

No response

Relevant log output

Exception 0xc0000005 0x1 0x0 0x7ff6fdb1d478
PC=0x7ff6fdb1d478

signal arrived during external code execution

goroutine 85 gp=0xc000196280 m=6 mp=0xc000188600 [syscall]:
runtime.cgocall(...)
	runtime/cgocall.go:369 +0x5e fp=0xc001a44ea8 sp=0xc001a44e70 pc=0x463cde
github.com/mattn/go-sqlite3._Cfunc__sqlite3_step_internal(...)
	_cgo_gotypes.go:620 +0x56 fp=0xc001a44ec8 sp=0xc001a44ea8 pc=0x893356
github.com/mattn/go-sqlite3.(*SQLiteRows).nextSyncLocked(...)
	sqlite3.go:2233 +0x53 fp=0xc001a44f08 sp=0xc001a44ec8 pc=0x898ef3
github.com/mattn/go-sqlite3.(*SQLiteRows).Next(...)
	sqlite3.go:2205 +0x56 fp=0xc001a44f28 sp=0xc001a44f08 pc=0x898ea6
database/sql.(*Rows).Next(...)
	sql.go:3197 +0x104 fp=0xc001a44f68 sp=0xc001a44f28 pc=0x6b1e24
github.com/syncthing/syncthing/internal/db/sqlite.(*folderDB).needSizeRemote(...)
	folderdb_counts.go:100 +0xc6 fp=0xc001a44fd0 sp=0xc001a44f68 pc=0xb78226
github.com/syncthing/syncthing/internal/db/sqlite.(*folderDB).CountNeed(...)
	folderdb_counts.go:38 +0x91 fp=0xc001a45008 sp=0xc001a44fd0 pc=0xb77b91
github.com/syncthing/syncthing/lib/model.(*folderSummaryService).sendSummary(...)
	folder_summary.go:404 +0x137 fp=0xc001a450a0 sp=0xc001a45008 pc=0xd7aaf7
github.com/syncthing/syncthing/lib/model.(*folderSummaryService).calculateSummaries(...)
	folder_summary.go:333 +0x10b fp=0xc001a450d8 sp=0xc001a450a0 pc=0xd7a8ab
github.com/syncthing/syncthing/lib/model.(*folderSummaryService).Serve(...)
	folder_summary.go:90 +0x14a fp=0xc001a45110 sp=0xc001a450d8 pc=0xd799ca

Activity

  1. added
    bug
    needs-triage
    on Mar 6, 2026
  2. added theissue type on Mar 6, 2026
  3. pulpier commented on Mar 6, 2026

    @pulpier
    Author

    Update: crash persists after removing and re-creating the devel folder

    Attempted workaround: removed the devel folder (the one that leads to the crash) from Syncthing and re-added it pointing to a fresh empty directory (devel.new). The crash continued immediately once syncing started again.

    The crash fires on every device connect/reconnect event that triggers calculateSummaries.

    Additional crash instances from today (2026-03-06):

    Crash at 05:43:03 (right after NAT detection, before devel folder was involved):

    Exception 0xc0000005 0x1 0x0 0x7ff6fdb1d478
    PC=0x7ff6fdb1d478
    signal arrived during external code execution
    
    runtime.cgocall(0x7ff6fdafcee0, 0xc0053889b8)
            runtime/cgocall.go:167 +0x3e
    github.com/mattn/go-sqlite3._Cfunc__sqlite3_step_internal(0x2a371e1e1e8)
            _cgo_gotypes.go:380 +0x50
    github.com/mattn/go-sqlite3.(*SQLiteRows).nextSyncLocked(0xc004e4da40, ...)
            sqlite3.go:2233 +0x76
    ...
    github.com/syncthing/syncthing/internal/db/sqlite.(*folderDB).needSizeRemote(...)
            folderdb_counts.go:100 +0x1c8
    github.com/syncthing/syncthing/lib/model.(*folderSummaryService).calculateSummaries(...)
            folder_summary.go:323 +0x1df
    

    Crash at 06:51:48 (after new device connection established to xxx):

    Exception 0xc0000005 0x8 0xa1e85ff484 0xa1e85ff484
    PC=0xa1e85ff484
    signal arrived during external code execution
    
    runtime.cgocall(0x7ff6fdafcee0, 0xc0009ce9b8)
    github.com/mattn/go-sqlite3._Cfunc__sqlite3_step_internal(0x28af320ecc8)
    github.com/mattn/go-sqlite3.(*SQLiteRows).nextSyncLocked(0xc0024ba720, ...)
            sqlite3.go:2233 +0x76
    github.com/syncthing/syncthing/internal/db/sqlite.(*folderDB).needSizeRemote(...)
            folderdb_counts.go:100
    github.com/syncthing/syncthing/lib/model.(*model).folderCompletion(...)
            model.go:927
    github.com/syncthing/syncthing/lib/model.(*model).Completion(...)
            model.go:892
    github.com/syncthing/syncthing/lib/model.(*folderSummaryService).sendSummary(...)
            folder_summary.go:404
    github.com/syncthing/syncthing/lib/model.(*folderSummaryService).calculateSummaries(...)
            folder_summary.go:323
    

    Fault addresses across all crashes today: 0x0, 0x7ff6fdb1d478, 0xa1e85ff484, 0x977abff714, 0xdc41dff314, 0x1ead3ff5e4, 0x620afff7a4 — all different, strongly consistent with use-after-free or race condition on an SQLite prepared statement or database handle that is freed/reused concurrently.

  4. steadytao commented on Mar 6, 2026

    @steadytao
    Contributor

    The SQL seems fine. A 0xc0000005 inside sqlite3_step may point to a lifetime/concurrency problem (e.g. a prepared statement or DB handle being used while its being reused/closed) not bad data

    Two quick things that would help narrow it down:

    1. If you run Syncthing with GOMAXPROCS=1, does it still crash?
    2. Does it still crash with only one small test folder (or if folder summaries arent being calculated)?

    If it stops crashing with reduced concurrency, that would strongly suggest a stmt/connection reuse issue around the statement cache

  5. pulpier commented on Mar 6, 2026

    @pulpier
    Author

    Tested with GOMAXPROCS=1 — Syncthing still crashes with the same STATUS_ACCESS_VIOLATION in sqlite3_step_internal / needSizeRemote within minutes of startup.

    Does this rule out a pure multi-core scheduling/goroutine concurrency issue as the cause?

  6. pulpier commented on Mar 6, 2026

    @pulpier
    Author

    To answer question 2: I have multiple folders shared across devices, but the crash is only triggered by one specific folder. Unfortunately I can't reduce it to a small test case — it's a large development folder.

  7. pulpier commented on Mar 6, 2026

    @pulpier
    Author

    I ran Syncthing with STTRACE=model,db and captured the debug log for a full crash cycle. The timing is consistent:

    19:48:34  INF  Established secure connection (device=MAFMSPH ...)
    19:48:34  INF  Additional device connection (device=MAFMSPH ... count=2)
                  [thousands of DBG "Marking file as deleted" entries from ongoing scan]
    19:48:39  DBG  Marking file as deleted (path=kicad\board_stage_io_phone\.git\objects\...)
    19:48:44  CRASH  STATUS_ACCESS_VIOLATION in sqlite3_step_internal / needSizeRemote
    

    The crash occurs while the initial folder scan is actively writing entries to the DB ("Marking file as deleted"), and a device reconnect simultaneously triggers calculateSummaries → needSizeRemote.

  8. pulpier commented on Mar 6, 2026

    @pulpier
    Author

    Further update: I re-ran with all devices paused in Syncthing config to check whether device connection events are required to trigger the crash.

    The crash still occurred. The debug log shows no device connections at all in this run — only periodic Completion() calls from calculateSummaries interleaved with scan writes ("Marking file as deleted"):

    20:02:08  DBG  model Completion(MAFMSPH, "w3dsu-bonlz"): ...
    20:02:08  DBG  Marking file as deleted (path=evcc\node_modules\...)
    20:02:09  DBG  model Completion(75UFMG2, "w3dsu-bonlz"): ...
                  [scan writes continuing...]
    20:02:16  DBG  model Completion(GYNCM4L, "w3dsu-bonlz"): ...  ← last log entry before crash
    

    So the crash does not require an active device connection. It is reproducible with all devices paused, triggered solely by calculateSummaries running concurrently with the initial folder scan writing to the DB.

  9. calmh commented on Mar 7, 2026

    @calmh
    Member

    See if the build from this PR ^ makes a difference?

  10. pulpier commented on Mar 8, 2026

    @pulpier
    Author

    It seems to work better — haven't seen a crash yet.

  11. added a commit that references this issue on Mar 13, 2026
    9ffce6e
  12. added a commit that references this issue on Mar 21, 2026
    5e0cc7f
  13. added 2 commits that reference this issue on Apr 6, 2026
    4034ede
    2759dfa
  14. added a commit that references this issue on Jun 28, 2026
    a4dadaa
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

    bugneeds-triage

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions