Repository navigation
Description
What happened?
Extremely rarely (once a several months) I face SQLITE_BUSY and stopped folder because of that.
First I was under impression that this was due to my experiments with lower connections limit and auto-close DBs on idle, because this can introduce documented SQLITE_BUSY on WAL commit operations. This was not syncthing issue then.
But these days for the first I faced exactly the same on vanilla git release 2.0.13, with binary from the releases. Log output attached.
Googling the issue, I've got the impression that it is never zero probability to get this error in SQLite. It is kind of "transaction deadlock / aborted / retry" in pretty much every db on earth. Can happen extremely rarely, but never - "never". Given that, it seems that maybe either one of the resolutions may be helpful here:
- add metrics/counters to gain global understanding if this is a some specific platform / toolset / Go vession / SQLite version / etc problem, and treat it as a toolset anomaly (i.e. not treat at all or search upstream solutions),
or,
- retry transactions as you usually do in almost any real world app,
or at least,
- just restart the folder - it seems unavoidable anyway because the only user-side resolution will be to restart Syncthing, so why not do it internally anyway.
Syncthing version
2.0.13
Platform & operating system
Windows 11
Browser version
No response
Relevant log output
2026-01-16 08:52:28 WRN Error on folder (error="getglobalfile: database is locked (5) (SQLITE_BUSY)" folder.id=Projects folder.type=sendreceive log.pkg=model)
2026-01-16 08:52:28 WRN Folder is in error state (folder=Projects error="getglobalfile: database is locked (5) (SQLITE_BUSY)" log.pkg=model)
Activity
calmh commentedon Jan 16, 2026
I was going to say "this should never happen", but you say that's not the case. I'll modify that to "I don't understand why that would happen", especially not for what is in this case a read-only call I believe. Need to understand better when and why this would happen, in order to handle it appropriately.
dmih commentedon Jan 16, 2026
Yes I recall your ideas that you "write from the one thread" or like that, If I am not recalling it wrong, that should avoid this.
That's why my first proposal is to find out how often this really happen and to check if that is not my personal hallucination. I see no ways to confirm such a rare bug except to add a counter to this event and see if it happens live except in "my lab", and if yes than how often and where.
From my side I only can ensure I re-checked it was not my "dirty" build.
dmih commentedon Jan 16, 2026
Correct me if I am wrong:
you do all write ops with under updateLock.Lock, including wal_checkpoint.
That's good because checkpoint can lead to SQL_BUSY on writers with high probability (and also another writes, for sure)
But I don't see any lock on read threads. So in effect you can keep reading while wal_checkpoint is in progress.
There is a lot smaller, but not zero probability of getting SQL_BUSY there.
In PASSIVE checkpoint mode, readers cannot get BUSY. But you are doing RESTART checkpoint, It can harm readers as it seems.
calmh commentedon Jan 17, 2026
Aha, that could be it
tbodt commentedon Jul 20, 2026
Simply add
busy_timeout = 5000here, then sqlite will automatically retry for up to 5 seconds instead of immediately returning SQLITE_BUSYsyncthing/internal/db/sqlite/folderdb_open.go
Line 29 in 578cc5a