Add immediate transaction lock mode to SQLite backend#450
Merged
cschleiden merged 2 commits intomainfrom Oct 24, 2025
Merged
Conversation
Copilot
AI
changed the title
[WIP] Adjust SQLite settings for enhanced connection handling
Add immediate transaction lock mode to SQLite backend
Oct 24, 2025
Owner
|
!bench !large |
Benchmark ResultsSQLite run
Large SQLite payload run (1MB)
Redis run
Large Redis payload run (1MB)
|
Owner
|
!bench !large !verylarge !skipmysql !skipredis |
Benchmark ResultsSQLite run
Large SQLite payload run (1MB)
Very Large SQLite payload run (5MB)
|
Co-authored-by: cschleiden <2201819+cschleiden@users.noreply.github.com>
Co-authored-by: cschleiden <2201819+cschleiden@users.noreply.github.com>
2148a51 to
92af8d8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Since enabling WAL mode, the SQLite backend can handle multiple connections, but this often leads to "database locked" errors under concurrent access. The root cause is that SQLite uses deferred transactions by default, which don't acquire write locks until the first write statement executes. By that time, there may be another non-reconcilable transaction in progress, and no retry is possible.
Solution
This PR adds the
_txlock=immediateparameter to all SQLite DSN connection strings. With immediate transaction locking, write locks are acquired immediately when a transaction begins (BEGIN), rather than being deferred until the first write operation.Combined with the existing
busy_timeout=5000pragma, this allows for proper serialization of concurrent writes. When a transaction attempts to acquire a lock and finds one already held, it will wait up to 5 seconds (the busy timeout period) for the lock to become available, significantly reducing database locked errors.Changes
NewInMemoryBackend()to include&_txlock=immediatein the in-memory database DSNNewSqliteBackend()to include?_txlock=immediatein the file-based database DSNTesting
References
This approach was validated in production use by the ConduitIO/conduit project.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.