Skip to content

fix(adonet): prevent SQLite transaction leaks - #11354

Merged
ReubenBond merged 6 commits into
dotnet:mainfrom
ReubenBond:rb-issue-11350-fix-sqlite-transaction-leak
Oct 2, 2026
Merged

ReubenBond merged 6 commits into
dotnet:mainfrom
ReubenBond:rb-issue-11350-fix-sqlite-transaction-leak

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Fixes #11350.

Problem

SQLite WriteToStorageKey opened a transaction using command-text BEGIN TRANSACTION. Writer contention could stop the batch before COMMIT, returning an untracked open transaction to the Microsoft.Data.Sqlite connection pool. Reusing that connection caused later writes to fail and allowed clears to be acknowledged without becoming durable.

Solution

Stage each write in a connection-private TEMP table and apply the mutation and version bookkeeping through a TEMP trigger. The request insertion and trigger effects execute as one implicit transaction; subsequent statements only read the TEMP result. Preserve optimistic-concurrency, full-identity matching, and scalar-version semantics.

Make the original SQLite main and persistence scripts idempotent so operators can reapply them to refresh all three persistence queries while preserving grain state. Add focused regression coverage for pooled-connection contention, durable clears, version progression, and script reapplication.

Rationale

A single-statement mutation avoids leaking explicit transactions and prevents a trailing write-lock failure after a durable mutation. Reapplying the original scripts installs the corrected queries while keeping database setup and upgrade timing under application control.

Copilot AI balanced review requested due to automatic review settings September 29, 2026 08:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation addresses the transaction leak while preserving write-version semantics and adds focused regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes SQLite transaction leaks during contended ADO.NET grain-state writes.

Changes:

  • Replaces explicit transactions with an atomic trigger-driven write.
  • Adds pooled-connection contention and durability coverage.
File Description
src/​AdoNet/​Orleans.Persistence.AdoNet/​Sqlite-Persistence.sql Stages writes in a temporary table and applies them through a trigger.
test/​Extensions/​Orleans.AdoNet.Tests/​Persistence/​SqlitePersistenceQueryTests.cs Verifies failed writes do not poison pooled connections.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 08:44
@ReubenBond
ReubenBond force-pushed the rb-issue-11350-fix-sqlite-transaction-leak branch from 7157083 to 44dbaa2 Compare October 2, 2026 08:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation addresses the reported leak while preserving concurrency semantics with focused regression coverage.

Review effort: Balanced
Findings: None

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request
Lines 82.93% (115,570 / 139,353)
Branches 72.26% (33,588 / 46,479)

Report-only conclusion: current-main baseline stale.

The newest successful coverage run tested a1a4676, not current main d4e4620.

Coverage combines every CI test matrix job, including providers, CodeGen, .NET 8/10, Linux, Windows, and macOS, using canonical physical source and branch identities.

The comparison remains report-only while normal line and branch variance is calibrated.

Coverage details

Copilot AI balanced review requested due to automatic review settings October 2, 2026 17:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The concurrency-sensitive transactional SQL and live database upgrade path warrant final human validation despite strong regression coverage.

Review effort: Balanced
Findings: None

Copilot AI balanced review requested due to automatic review settings October 2, 2026 18:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation addresses the transaction leak while preserving concurrency semantics and includes comprehensive regression coverage.

Review effort: Balanced
Findings: None

Copilot AI balanced review requested due to automatic review settings October 2, 2026 18:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The transaction-leak fix, upgrade path, startup validation, documentation, and regression coverage are consistent and complete.

Review effort: Balanced
Findings: None

Copilot AI balanced review requested due to automatic review settings October 2, 2026 21:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The atomic write design addresses the transaction leak while preserving concurrency and version semantics with focused regression coverage.

Review effort: Balanced
Findings: None

@ReubenBond
ReubenBond merged commit d4e4620 into dotnet:main Oct 2, 2026
80 checks passed
@ReubenBond
ReubenBond deleted the rb-issue-11350-fix-sqlite-transaction-leak branch October 2, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQLite persistence: a failed WriteToStorageKey leaves its transaction open on a pooled connection, so later writes fail or are silently lost

2 participants