Repository navigation
Prevent pooling SQLite connections with unsettled native transactions - #39083
Merged
AndriySvyryd merged 1 commit intoSep 26, 2026
Merged
Conversation
- Discard handles whose native transaction remains active at pool return. - Preserve rollback errors and reuse of healthy or recovered connections. - Cover sync/async rollback and disposal, plus unmanaged transactions. Fixes dotnet#39082
This was referenced Sep 24, 2026
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved review issues remain, and the supplied validation passed.
Review effort: Lite
Findings: None
What changed in this PR
Prevents SQLite connections with active native transactions from being returned to the pool after rollback failures.
Changes:
- Detects unsettled native transactions and disposes affected handles.
- Adds regression and control coverage for rollback, disposal, recovery, and raw SQL scenarios.
| File | Description |
|---|---|
test/Microsoft.Data.Sqlite.Tests/SqliteConnectionFactoryTest.cs |
Adds pooling and transaction regression coverage. |
src/Microsoft.Data.Sqlite.Core/SqliteConnectionInternal.cs |
Rejects handles with active native transactions from pooling. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
AndriySvyryd
approved these changes
Sep 26, 2026
Member
|
Thanks for your contribution! |
This was referenced Sep 27, 2026
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.
Fixes #39082
When native rollback fails,
SqliteTransaction.RollbackInternalstill completes and detaches its managed transaction wrapper. Closing the connection can then return a handle with an active transaction to the pool. The next borrower can see uncommitted rows and cannot start a new transaction.Check
sqlite3_get_autocommitduring deactivation, after resetting connection-specific state and inside the existing valid-handle guard. Mark an unsettled handle non-poolable so the existing return path disposes it. This preserves the rollback exception and affects only that physical connection. A connection whose native transaction has successfully ended remains reusable, including one explicitly recovered by the caller after an earlier rollback error.Add ten regression/control cases covering sync/async rollback and disposal, rejected and successful native rollback, healthy connections in the same pool, caller recovery before close, and raw SQL transactions. Tests use SQLite's authorizer to reject ROLLBACK before execution; the failure is raised by the native engine.
Validation on Windows x64 with the pinned upstream SDK:
category=failingexclusion.Builds have zero warnings/errors. Alternate native SQLite bundles and upstream CI have not been run. There is no public API change, rollback retry or pool-wide clearing; pool return adds one native autocommit check.
AI disclosure
The issue was found and the fix, regression tests, and PR were developed with GPT-6 Astra on Extra High, with the repository owner's authorization.
Checklist