Repository navigation
Microsoft.Data.Sqlite: Don't retry SQLITE_BUSY_SNAPSHOT - #39587
Open
ajcvickers wants to merge 2 commits into
Open
ajcvickers wants to merge 2 commits into
ajcvickers wants to merge 2 commits into
Conversation
Contributor
Author
|
/cc @bricelam |
When a connection holding a read transaction tries to write after another connection has committed, SQLite reports SQLITE_BUSY with the extended code SQLITE_BUSY_SNAPSHOT. The read snapshot stays stale until the reading transaction ends, so the busy-retry loops could never succeed and only delayed the error until the command timeout (30 seconds by default). Fail immediately instead. Part of dotnet#29514 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ajcvickers
force-pushed
the
sqlite-fail-fast-busy-snapshot
branch
from
November 14, 2026 11:40
c054fc8 to
aca42e2
Compare
- Move the tests that aren't about transactions to SqliteCommandTest and share the WAL TempDatabase helper through TestUtilities. - Run the zero-timeout test with a cancellation token so that a regression fails instead of hanging the test run. - Dispose the other connection's transaction and await the background rollback in a finally block. - Don't let TempDatabase cleanup failures mask the real test failure. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Part of #29514
When a connection that has an open read transaction (an unfinished data reader, or a deferred transaction that has already read) tries to write after another connection has committed, SQLite returns
SQLITE_BUSYwith the extended codeSQLITE_BUSY_SNAPSHOT(517). This can only happen in WAL mode, and the read snapshot stays stale until the reading transaction ends, so retrying can never succeed.Microsoft.Data.Sqlite retries
SQLITE_BUSYitself rather than usingsqlite3_busy_timeout, so it kept retrying for the whole command timeout (30 seconds by default, and forever when the timeout is 0) before throwing exactly the same exception.This PR makes the statement step loop in
SqliteDataReaderthrow immediately forSQLITE_BUSY_SNAPSHOT. PlainSQLITE_BUSY,SQLITE_LOCKEDandSQLITE_LOCKED_SHAREDCACHEare retried as before.What is deliberately not changed
SqliteCommandandRetryWhileBusyinSqliteConnectionInternal: preparing a statement doesn't start a write transaction andRetryWhileBusyonly runs against fresh connections at open, so neither can see this error.SqliteDataRecord: that statement already holds the write lock, so it can't fail with a stale snapshot. A comment explains the choice of overload.Tests
New tests in
SqliteTransactionTestcoverBeginTransaction(), a write, an async write, a write withCommandTimeout = 0, and a write in a deferred transaction after the reader is disposed, each asserting it fails in well under the timeout. Two contrast tests show a write blocked by another writer in WAL mode is still retried (and still times out asSQLITE_BUSYif the other writer doesn't finish). I confirmed the async and deferred tests take the full 30 seconds without the fix.Related
A separate PR, #39588, adds the extended error code and guidance to the exception message so the cause is easier to find. The two are independent.
🤖 Generated with Claude Code