fix(db): ensure transaction depth resets when rollback fails - #1725
Open
xiaobaZeo wants to merge 1 commit into
Open
fix(db): ensure transaction depth resets when rollback fails#1725xiaobaZeo wants to merge 1 commit into
xiaobaZeo wants to merge 1 commit into
Conversation
Guarantee that NodeSqliteAdapter._txDepth always resets to 0 via try/finally, preventing transaction isolation loss on subsequent operations if SQLite aborts the transaction before rollback completes. Co-Authored-By: Claude Code <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.
Summary
In
NodeSqliteAdapter.transaction()(src/db/sqlite-adapter.ts), if a transaction encounters an error and SQLite automatically aborts the transaction before a rollback is executed, callingROLLBACKthrows an error (cannot rollback - no transaction is active). Previously,this._txDepth = 0was placed afterthis._db.exec('ROLLBACK')without afinallyblock, causing_txDepthto remain greater than 0 on error. As a consequence, subsequenttransaction()calls on the same connection falsely assumed they were inside a nested transaction and omittedBEGIN/COMMIT, degrading operations to auto-commit and violating ACID isolation.This PR wraps the rollback and depth reset in a
finallyblock with acommittedflag, ensuring:_txDepthis guaranteed to reset to 0 regardless of closure errors, commit failures, or rollback failures.__tests__/sqlite-backend.test.tscovering both standard rollback and pre-aborted transaction scenarios.CHANGELOG.mdunder## [Unreleased].Validation
npx vitest run __tests__/sqlite-backend.test.tspasses (4 tests passed).npm run buildsucceeds cleanly.🤖 Generated with Claude Code