Skip to content

Conversation

@davidrothera
Copy link
Contributor

@davidrothera davidrothera commented Feb 10, 2026

When connections are created inside GRDB DatabasePool instances, they are done lazily for both read and write connections.

At the moment, in attachMetadatabase, we are creating a short-lived DatabasePool and instantly using it for a write connection to execute SELECT 1 in order to ensure the database exists and is functional.

The issue with this is that write connections require an exclusive lock on the file; usually, this is not an issue as when using a single DatabasePool instance, these are queued serially, but if one of these lazy connections is created at the same time as another DatabasePool instance has the database locked, we end up with a SQLite exception:

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

This PR changes that connection to a read one, which, with WAL enabled databases, can leverage the shared memory file and "play nicely" with other threads.

Fixes #394

@davidrothera davidrothera marked this pull request as ready for review February 10, 2026 15:23
@stephencelis stephencelis merged commit 9847686 into pointfreeco:main Feb 10, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants