Repository navigation
fix(sqlite): synchronize transaction depth when SQLite auto-rolls back - #4473
Open
webdevsamran wants to merge 1 commit into
Open
webdevsamran wants to merge 1 commit into
webdevsamran wants to merge 1 commit into
Conversation
When SQLite encounters errors such as SQLITE_FULL, SQLITE_IOERR, or SQLITE_CORRUPT during a statement execution, it automatically rolls back the active transaction and resets autocommit mode to active (1). Previously, when the application or Transaction drop guard subsequently invoked rollback or commit, SQLx attempted to execute a ROLLBACK / RELEASE statement. Because no SQLite transaction was active, the statement failed, leaving shared.transaction_depth stuck at its previous value (>= 1). Subsequent attempts to start transactions via begin_with failed with InvalidSavePointStatement. This change updates the SQLite connection worker: - In Command::Rollback, if depth > 0 but !conn.handle.in_transaction(), reset shared.transaction_depth to 0 and treat the rollback as Ok(()). - In Command::Commit, if res.is_err() and !conn.handle.in_transaction(), reset shared.transaction_depth to 0. - In Command::Begin, synchronize depth to 0 if !conn.handle.in_transaction(). - Adds regression test reproducing SQLITE_FULL via page limit. Fixes transact-rs#4434 Signed-off-by: Samran Asif <samranwebdev2000@gmail.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.
Does your PR solve an issue?
Fixes #4434
Is this a breaking change?
No. This fixes stale transaction state when SQLite automatically rolls back a transaction on fatal errors (such as
SQLITE_FULL,SQLITE_IOERR, orSQLITE_CORRUPT).Description
When SQLite encounters errors that cause an automatic rollback (such as
SQLITE_FULLorSQLITE_CORRUPT), SQLite turns autocommit mode back ON. When the application or transaction drop guard subsequently calls rollback/commit, SQLx attempted to execute a rollback query against SQLite which failed withcannot rollback - no transaction is active. Because the query failed,shared.transaction_depthwas not decremented and remained permanently stale (depth >= 1). Any subsequent attempt to begin a new transaction (especially with custom statements likebegin_with("BEGIN IMMEDIATE")) immediately failed withInvalidSavePointStatement.This change:
Command::Rollback: ifdepth > 0and!conn.handle.in_transaction(), resetsshared.transaction_depthto 0 and treats rollback as successful.Command::Commit: if commit fails and!conn.handle.in_transaction(), resetsshared.transaction_depthto 0.Command::Begin: synchronizestransaction_depthto 0 if SQLite is not currently in a transaction.tests/sqlite/sqlite.rsreproducing the automatic rollback viaPRAGMA max_page_count.