You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(database): roll back transactions on JVM errors - #47
A JVM Error inside runTransaction previously skipped rollback, and restoring auto-commit then committed partial SQLite writes. Roll back SQL exceptions, runtime exceptions and errors; restore auto-commit only after a successful commit or rollback. If rollback fails, close/discard the connection and preserve the original failure alongside cleanup failures.
Validation: real SQLite Error-after-INSERT/reopen and same-connection recovery regressions, failed-rollback/cleanup cases; local Java21 clean verify passes 241 tests with zero missed lines under the unchanged gate. Public API is unchanged, and only SqliteDatabase changes among all120 production classes; character/estate record bytes remain identical to TLibs2.6.0. Dependency pins, schemas and consumers are unchanged.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
📝 Summary
Summary by CodeRabbit
Bug Fixes
Improved database transaction handling when an operation fails, helping prevent incomplete changes from being saved.
Improved recovery when a transaction cannot be rolled back or database settings cannot be restored, reducing the risk of reusing a connection in an invalid state.
Preserved the original transaction error when additional failures occur during recovery.
runTransaction now handles SQL exceptions, runtime exceptions and errors during transaction work. It attempts rollback, restores auto-commit after successful completion, and discards the connection if rollback fails. Tests cover these paths with real SQLite databases and mocked JDBC connections.
Changes: SQLite transaction handling
Layer / File(s)
Summary
Transaction lifecycle and restoration src/main/java/net/tfminecraft/tlibs/database/SqliteDatabase.java, src/test/java/net/tfminecraft/tlibs/database/SqliteTransactionErrorTest.java
runTransaction rolls back after transaction-body failures and restores auto-commit after a successful commit or rollback. Tests cover errors from transaction work, connection reuse and persistence, and failures while restoring auto-commit.
Rollback failure and connection disposal src/main/java/net/tfminecraft/tlibs/database/SqliteDatabase.java, src/test/java/net/tfminecraft/tlibs/database/SqliteFailureTest.java, src/test/java/net/tfminecraft/tlibs/database/SqliteTransactionErrorTest.java
If rollback fails, runTransaction closes and discards the connection. Tests check exception wrapping, suppressed failures, and that auto-commit is not restored.
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
size:M30-99 effective changed lines (tests excluded in mixed PRs).
1 participant
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.
A JVM
ErrorinsiderunTransactionpreviously skipped rollback, and restoring auto-commit then committed partial SQLite writes. Roll back SQL exceptions, runtime exceptions and errors; restore auto-commit only after a successful commit or rollback. If rollback fails, close/discard the connection and preserve the original failure alongside cleanup failures.Validation: real SQLite Error-after-INSERT/reopen and same-connection recovery regressions, failed-rollback/cleanup cases; local Java21 clean verify passes 241 tests with zero missed lines under the unchanged gate. Public API is unchanged, and only SqliteDatabase changes among all120 production classes; character/estate record bytes remain identical to TLibs2.6.0. Dependency pins, schemas and consumers are unchanged.