Repository navigation
[Mocha] Fix the outbox worker missing messages written inside a TransactionScope - #10496
Merged
Merged
Conversation
Outbox writes inside a TransactionScope signal the outbox worker before the row is committed and never signal at commit, so the worker can park indefinitely with a committed message in the table.
Outbox writes and SaveChanges inside a TransactionScope now set the outbox signal when the ambient transaction completes instead of immediately, so the worker no longer wakes before the row is visible and parks with a committed message in the table.
Persisting many outbox messages in one TransactionScope no longer adds a completion handler per message, and a signal disposed during shutdown no longer throws out of the committed scope's Dispose.
Drop the per-transaction subscription tracking and the disposed-signal guard. Repeated signals collapse in the auto-reset event, so one completion handler per write is sufficient.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
Static review found no blocking issues, and regression tests cover both write paths and transaction completion, though they were not executed.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes Mocha outbox wakeups so messages written inside a TransactionScope can be dispatched after commit without waiting for another write.
Changes:
- Defers insert and
SaveChangessignals until ambient transaction completion. - Adds regression tests for commit, rollback, multiple messages, and worker delivery.
| File | Description |
|---|---|
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/PostgresOutboxAmbientTransactionSignalTests.cs | Adds transaction signaling and delivery tests. |
| src/Mocha/src/Mocha.EntityFrameworkCore/Outbox/OutboxSignalExtensions.cs | Centralizes deferred signaling. |
| src/Mocha/src/Mocha.EntityFrameworkCore/Outbox/OutboxSaveChangesInterceptor.cs | Defers signals after SaveChanges. |
| src/Mocha/src/Mocha.EntityFrameworkCore/Assembly.cs | Exposes the internal helper to the Postgres assembly. |
| src/Mocha/src/Mocha.EntityFrameworkCore.Postgres/Outbox/PostgresMessageOutbox.cs | Defers insert signals and updates documentation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
PascalSenn
approved these changes
Oct 6, 2026
The Postgres transport's own ThrowHelper shadows Mocha.ThrowHelper, which defines BeforeAndAfterConflict, so the build failed.
Contributor
Patch coverage90.9% of changed lines covered (10/11)
Uncovered changed lines (JSON){
"sha": "3f739125d6343fe71635cbc57af52b54d0faa6ac",
"files": [
{ "path": "src/Mocha/src/Mocha.Transport.Postgres/Descriptors/PostgresQueueDescriptor.cs", "ranges": [[127, 127]] }
]
}Project coverage: 58.5% (313834/536121 lines) |
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.
Outbox writes inside a
TransactionScopesignal the outbox worker before the transaction commits, and nothing signals it at commit. The worker wakes, finds no visible rows, and waits indefinitely, so the committed message is only dispatched after an unrelated write.This PR defers the signal until the ambient transaction completes, for both outbox inserts and
SaveChanges.