Skip to content

fix(streaming): serialize SQL Server queue commits - #10572

Merged
ReubenBond merged 1 commit into
dotnet:mainfrom
ReubenBond:rb-fix-sql-stream-flake
Aug 13, 2026
Merged

ReubenBond merged 1 commit into
dotnet:mainfrom
ReubenBond:rb-fix-sql-stream-flake

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

Fixes #10568.

Concurrent SQL Server stream enqueues allocate their message IDs before their transactions commit. A later ID can therefore become visible first, allowing the pulling-agent cache to advance before an older row appears and violating its monotonic sequence-token invariant.

This change serializes message ID allocation and insertion commits per logical SQL Server queue using a transaction-owned application lock. Independent queues remain concurrent, while each queue now exposes IDs in allocation order. A focused regression holds one enqueue transaction open, verifies a competing enqueue cannot allocate an ID, then confirms dequeue order after the first commit.

Microsoft Reviewers: Open in CodeFlow

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 13, 2026 04:05

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.

Pull request overview

This PR fixes a SQL Server ADO.NET streaming ordering bug where concurrent enqueues could make later MessageIds visible before earlier ones, breaking the stream cache’s monotonic sequence-token assumptions. It does so by serializing MessageId allocation + insert visibility per logical queue using a transaction-owned SQL Server application lock, and adds a focused regression test to validate the behavior.

Changes:

  • Update QueueStreamMessage (SQL Server) to acquire a per-queue sp_getapplock (transaction-owned) before allocating NEXT VALUE FOR and inserting, ensuring visibility follows allocation order per queue.
  • Add a SQL Server-only regression test which holds one enqueue transaction open, confirms a competing enqueue cannot proceed immediately, then validates dequeue ordering after commit.
Show a summary per file
File Description
test/Extensions/Orleans.AdoNet.Tests/Streaming/RelationalOrleansQueriesTests.cs Adds a SQL Server regression verifying enqueue serialization and resulting monotonic ordering.
src/AdoNet/Orleans.Streaming.AdoNet/SQLServer-Streaming.sql Serializes per-queue message ID allocation/insert using a transaction-owned application lock to preserve monotonic visibility.

Review details

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

@ReubenBond
ReubenBond merged commit e666961 into dotnet:main Aug 13, 2026
73 checks passed
@ReubenBond
ReubenBond deleted the rb-fix-sql-stream-flake branch August 13, 2026 14:02
This was referenced Aug 28, 2026
This was referenced Sep 7, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 14, 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.

Flaky test: SQL Server AdoNet_11 stream delivery times out

2 participants