Repository navigation
Closed
Labels
bugA problem with current functionality, as opposed to missing functionality (enhancement)needs-triageNew issues needed to be validated
Description
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
- Run Syncthing v2.0.16-rc.1 on Windows 11
- Have at least one folder configured for sync
- 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=0xd799caMetadata
Metadata
Assignees
Labels
bugA problem with current functionality, as opposed to missing functionality (enhancement)needs-triageNew issues needed to be validated
Activity
pulpier commentedon Mar 6, 2026
Update: crash persists after removing and re-creating the devel folder
Attempted workaround: removed the
develfolder (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):
Crash at 06:51:48 (after new device connection established to xxx):
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.steadytao commentedon Mar 6, 2026
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:
If it stops crashing with reduced concurrency, that would strongly suggest a stmt/connection reuse issue around the statement cache
pulpier commentedon Mar 6, 2026
Tested with
GOMAXPROCS=1— Syncthing still crashes with the sameSTATUS_ACCESS_VIOLATIONinsqlite3_step_internal/needSizeRemotewithin minutes of startup.Does this rule out a pure multi-core scheduling/goroutine concurrency issue as the cause?
pulpier commentedon Mar 6, 2026
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.
pulpier commentedon Mar 6, 2026
I ran Syncthing with
STTRACE=model,dband captured the debug log for a full crash cycle. The timing is consistent: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.pulpier commentedon Mar 6, 2026
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 fromcalculateSummariesinterleaved with scan writes ("Marking file as deleted"):So the crash does not require an active device connection. It is reproducible with all devices paused, triggered solely by
calculateSummariesrunning concurrently with the initial folder scan writing to the DB.chore(sqlite): reduce max open connections, keep them open permanently
calmh commentedon Mar 7, 2026
See if the build from this PR ^ makes a difference?
pulpier commentedon Mar 8, 2026
It seems to work better — haven't seen a crash yet.
chore(sqlite): reduce max open connections, keep them open permanently (
Merge branch 'main' into jb/newconfigsettings
chore(sqlite): reduce max open connections, keep them open permanently (
chore(sqlite): reduce max open connections, keep them open permanently (
fix(container): update image syncthing/syncthing (2.0.13 → 2.0.16) (#179
[codex] Merge upstream stable v2.1.1 into main (#23)