Repository navigation
[Mocha] Fix PostgreSQL outbox persistence connection lifetime - #10478
Merged
Merged
Conversation
Balance EF connection opening and closing in guaranteed cleanup so persistence preserves caller-owned connections and transaction enlistment. Add direct PostgreSQL regression coverage for ambient and explicit transaction atomicity, pooled factory contexts, repeated persistence, failures, and cancellation with prepared transactions disabled.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused lifecycle fix is comprehensively covered across success, failure, cancellation, and transaction scenarios.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes PostgreSQL outbox connection leaks while preserving caller-managed connections and transaction enlistment.
Changes:
- Balances EF-managed connection opening and closing with guaranteed cleanup.
- Adds PostgreSQL regression coverage for transactions, pooling, failures, and cancellation.
| File | Description |
|---|---|
PostgresOutboxConnectionLifetimeTests.cs |
Adds connection-lifetime regression tests. |
Mocha.EntityFrameworkCore.Postgres.Tests.csproj |
Adds snapshot-testing dependencies. |
PostgresMessageOutbox.cs |
Restores connection state after persistence. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Patch coverage100.0% of changed lines covered (17/17)
Project coverage: 57.9% (300812/519757 lines) |
PascalSenn
approved these changes
Oct 4, 2026
glen-84
pushed a commit
that referenced
this pull request
Oct 8, 2026
This was referenced Oct 10, 2026
Merged
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.
When the outbox opens a database connection to store a message, it leaves that connection open. An application may use a scoped context for the outbox and separate contexts from
IDbContextFactoryfor repository operations, all within oneTransactionScope. A later repository operation then opens another connection while the outbox connection is still open and can fail with “prepared transactions are disabled”.The outbox now closes connections it opens after persistence, including on failure or cancellation. Connections already open remain open, and application writes and outbox messages still commit or roll back together.