Repository navigation
Conversation
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.
When a statement fails with SQLITE_FULL (and a few other errors), SQLite rolls the whole transaction back by itself. The worker still thinks it is inside the transaction, so when the
Transactionis dropped it sendsROLLBACK(orROLLBACK TOfor a savepoint), that fails with "no transaction is active" / "no such savepoint", andtransaction_depthis never decremented. After that the connection is stuck:begin_with(...)always returnsInvalidSavePointStatementandbegin()issues aSAVEPOINTinstead ofBEGIN.Reproduction from the issue, in short:
The rollback handler now checks
sqlite3_get_autocommit(in_transaction(), already used for customBEGIN) first. If depth is non-zero but SQLite is no longer in a transaction, it resets the depth to 0 and reports success instead of running a rollback that can only fail. A failedcommit()leaves theTransactionopen, so its drop goes through the same path.Added
it_can_recover_from_automatic_rollbackintests/sqlite/sqlite.rs, which hits SQLITE_FULL inside a nested transaction and then callsbegin_with("BEGIN IMMEDIATE"). On main it fails withattempted to call begin_with at non-zero transaction depth. With the change, the SQLite test suite (--features any,macros,migrate,sqlite,_unstable-all-types,runtime-tokio,sqlite-preupdate-hook),cargo test -p sqlx-sqlite --all-features, clippy with-D warningsandcargo fmt --checkall pass locally.Does your PR solve an issue?
fixes #4434
Is this a breaking change?
No. The only behavior change is that rolling back a transaction SQLite has already rolled back returns
Ok(())and leaves the connection usable, where before it returned an error and left the connection unable to start a new transaction.