Skip to content

fix(database): roll back transactions on JVM errors - #47

Merged
ryanbarlow97 merged 2 commits into
mainfrom
stage6c/transaction-errors
Oct 14, 2026
Merged

ryanbarlow97 merged 2 commits into
mainfrom
stage6c/transaction-errors

Conversation

@ryanbarlow97

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the size:M 30-99 effective changed lines (tests excluded in mixed PRs). label Oct 14, 2026
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 13 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6dc0830d-ae1a-4c16-9781-166c84ed3a2f
📥 Commits

Reviewing files that changed from the base of the PR and between 691a380 and 25a7f95.

📒 Files selected for processing: 2
  • src/main/java/net/tfminecraft/tlibs/database/SqliteDatabase.java
  • src/test/java/net/tfminecraft/tlibs/database/SqliteSelfRollbackTest.java

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f0db6b34-68e4-4386-b5b0-177d435ad99c
📥 Commits

Reviewing files that changed from the base of the PR and between 3d1e98c and 691a380.

📒 Files selected for processing: 3
  • 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

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.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 691a3

This change makes SQLite transactions roll back when a JVM error occurs, and no merge-blocking risk was found.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Oct 14, 2026
@ryanbarlow97
ryanbarlow97 merged commit 5844437 into main Oct 14, 2026
5 checks passed
@ryanbarlow97
ryanbarlow97 deleted the stage6c/transaction-errors branch October 14, 2026 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 effective changed lines (tests excluded in mixed PRs).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant