Skip to content

Concurrent access to database with metadatabase enabled causes "database is locked" exception #394

@davidrothera

Description

@davidrothera

Description

In projects which have the metadatabase attached as per the recommended method inside prepareDatabase along with multi-threaded usage of that database it can result in issues where the meta db is locked.

SQLite error 5: database is locked - while executing `BEGIN IMMEDIATE TRANSACTION`

I believe this is because in the attach method we create a short lived pool and that is not shared between prepare calls so cant properly pool/queue the requests.

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • I have determined whether this bug is also reproducible in a vanilla GRDB project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

No issue

Actual behavior

Intermittent issues

Reproducing project

https://github.com/davidrothera/LockedDatabaseRepro

SQLiteData version information

1.5.1

Sharing version information

No response

GRDB version information

7.9.0

Destination operating system

No response

Xcode version information

No response

Swift Compiler version information

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions