Skip to content

fix(streaming): prevent ADO.NET stream message loss on out-of-order dequeue - #11527

Merged
ReubenBond merged 3 commits into
dotnet:mainfrom
ScarletKuro:fix/adonet-streaming-message-order
Oct 21, 2026
Merged

ReubenBond merged 3 commits into
dotnet:mainfrom
ScarletKuro:fix/adonet-streaming-message-order

Conversation

@ScarletKuro

@ScarletKuro ScarletKuro commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

The ADO.NET stream provider used the database MessageId as the sequence token. SimpleQueueCache assumes tokens increase in the order messages are dequeued, and MessageId doesn't:

  • SQL Server OUTPUT and PostgreSQL RETURNING don't guarantee row order, so a single read can come back out of order and the cursor skips the older rows.
  • A message can become visible again after newer ones are already cached: released by a silo that's shutting down, visibility timeout, retry after a delivery failure, or a late commit. The cache then reports a miss for a message it actually holds, and a later purge confirms and deletes it without it ever being delivered.
  • If an attempt and its redelivery are both in the cache, purging them sends the same MessageId twice in one confirmation batch. Every provider rejects that with a primary-key violation, so nothing in the batch gets confirmed.

The result is consumers silently missing messages, mostly around silo shutdown and queue rebalancing. This matches the ADO.NET reports in #9126.

Changes:

  • The receiver assigns each dequeued message a position from a provider-wide counter and uses it as the token. Within a read, messages are still ordered by MessageId.
  • AdoNetBatchContainer keeps the MessageId in a non-serialized field for confirmation.
  • AdoNetStreamPositions maps positions back to message IDs for the failure handler. If a position no longer resolves, the handler skips it.
  • Confirmations are deduplicated by MessageId, keeping the highest dequeue count. That's the only count the database row will accept.

Tokens are still EventSequenceTokenV2 and the SQL scripts are unchanged, so mixed-version clusters and existing databases are fine. All changed types are internal. One behavior change: a token's SequenceNumber is now a local cache position, not the MessageId. The provider isn't rewindable and doesn't accept user tokens, so nothing should depend on that.

Related to #9126

Microsoft Reviewers: Open in CodeFlow

Copilot AI balanced review requested due to automatic review settings October 17, 2026 15:02

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

@ScarletKuro

ScarletKuro commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Do you want an end-to-end test for this too? Something like a two-silo cluster where one shuts down while it still has unconfirmed messages. There's nothing like that for ADO.NET streams right now. Problem is that the loss depends on timing tho.

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request Current main Variance
Lines 83.58% (119,077 / 142,464) 83.58% (119,037 / 142,429) +0.0075 pp
Branches 73.24% (35,452 / 48,406) 73.21% (35,432 / 48,398) +0.0292 pp

Report-only conclusion: improved.

The current-main baseline is commit fbe240c34e and uses the same reviewed coverage matrix.

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 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.

🔵 Needs a closer look

The token identity change warrants human validation across multi-silo shutdown, rebalancing, and mixed-version operation.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 19, 2026 21:04
@ReubenBond
ReubenBond force-pushed the fix/adonet-streaming-message-order branch from 50fadcc to 3b6466f Compare October 19, 2026 21:04

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

🟢 Approval recommended

Static review identified no blocking issues in ordering, position lifecycle, confirmation handling, or the regression tests.

No open issues 🎉

Review effort: Balanced

@ReubenBond
ReubenBond merged commit 3fe31e2 into dotnet:main Oct 21, 2026
94 checks passed
@ScarletKuro
ScarletKuro deleted the fix/adonet-streaming-message-order branch October 21, 2026 20:09
ReubenBond pushed a commit to ReubenBond/orleans that referenced this pull request Oct 22, 2026
ReubenBond pushed a commit that referenced this pull request Oct 23, 2026
…equeue (#11527)

(cherry picked from commit 3fe31e2)

Upstream-PR: #11527
Upstream-Commit: 3fe31e2
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants