Skip to content

Consider better reaction to SQLITE_BUSY #10529

Open

Description

@dmih

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:

  1. 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,

  1. retry transactions as you usually do in almost any real world app,

or at least,

  1. 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

  1. added theissue type on Jan 16, 2026
  2. added
    bug
    needs-triage
    on Jan 16, 2026
  3. calmh commented on Jan 16, 2026

    @calmh
    Member

    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.

  4. dmih commented on Jan 16, 2026

    @dmih
    Author

    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.

  5. dmih commented on Jan 16, 2026

    @dmih
    Author

    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.

  6. calmh commented on Jan 17, 2026

    @calmh
    Member

    Aha, that could be it

  7. tbodt commented on Jul 20, 2026

    @tbodt
    Contributor

    Simply add busy_timeout = 5000 here, then sqlite will automatically retry for up to 5 seconds instead of immediately returning SQLITE_BUSY

    "auto_vacuum = INCREMENTAL",

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