Skip to content

fix(streaming): release Azure Queue messages during handoff - #11144

Merged
ReubenBond merged 6 commits into
dotnet:mainfrom
ReubenBond:rb-issue-11119-fix-azure-queue-delivery
Sep 5, 2026
Merged

ReubenBond merged 6 commits into
dotnet:mainfrom
ReubenBond:rb-issue-11119-fix-azure-queue-delivery

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Sep 5, 2026 •

Copy link
Copy Markdown
Member

Fixes #11119.

Problem

When Azure Queue ownership moves to another silo, the previous receiver can shut down with prefetched, unacknowledged messages still hidden by their visibility timeout. The replacement pulling agent cannot receive those messages until the lease expires, which caused the multi-stream join test to observe 9 of 10 deliveries for its full 30-second deadline.

Solution

  • Track complete receiver operations so shutdown waits for receive, acknowledgement, and late-message release work.
  • Retain pending receipts until Azure confirms deletion.
  • Reset remaining message visibility to zero during graceful handoff, with bounded concurrency and the shutdown cancellation budget.
  • Release messages returned after shutdown begins instead of exposing them to the stopped receiver.
  • Add deterministic coverage for replacement delivery, late receive races, successful acknowledgement, and deletion failure, plus an Azurite-backed adapter regression.
  • Document graceful handoff behavior and the Azure Queue Update Message permission requirement.

Rationale

Graceful ownership transfer preserves at-least-once delivery while making unconfirmed work immediately available to the replacement receiver. Azure's existing visibility lease remains the recovery path for process failure or authorization/transport errors during release.

Microsoft Reviewers: Open in CodeFlow

Copilot AI lite review requested due to automatic review settings September 5, 2026 08:32

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

🟡 Changes recommended

The current shutdown-during-receive path can still perform message release using CancellationToken.None, which can ignore the shutdown budget and potentially hang shutdown/receive completion under stalled Azure operations.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 1 High severity

New issues introduced by this change (1)
Severity Finding
High severity src/​Azure/​Orleans.Streaming.AzureStorage/​Providers/​Streams/​AzureQueue/​AzureQueueAdapterReceiver.cs — When shutdown begins during a receive, this branch clears pendingDeliveries, which later triggers…
What changed in this PR

This PR addresses a reliability gap in the Azure Queue streaming receiver during graceful ownership handoff: prefetched but unacknowledged messages could remain hidden until their visibility timeout, delaying redelivery on the replacement silo and causing flaky “9 of 10 deliveries” timeouts.

Changes:

  • Update the Azure Queue receiver shutdown path to track in-flight operations and proactively release pending (unacknowledged) messages by resetting visibility.
  • Introduce an internal IAzureQueueDataManager seam and add message-release support in AzureQueueDataManager via UpdateMessageAsync.
  • Add targeted unit + Azurite-backed functional coverage and document graceful handoff behavior/permissions.
File Description
test/​Extensions/​Orleans.Azure.Tests/​Streaming/​AzureQueueAdapterTests.cs Adds an Azurite-backed functional regression test asserting pending messages are redelivered promptly after receiver shutdown.
test/​Extensions/​Orleans.Azure.Tests/​Streaming/​AzureQueueAdapterReceiverTests.cs Adds deterministic unit tests for shutdown release, late-receive races, successful delete, and delete-failure behavior.
src/​Azure/​Orleans.Streaming.AzureStorage/​Utilities/​AzureQueueErrorCode.cs Extends error-code IDs used by new shutdown/release logging.
src/​Azure/​Orleans.Streaming.AzureStorage/​Storage/​AzureQueueDataManager.cs Adds IAzureQueueDataManager and implements ReleaseQueueMessage via UpdateMessageAsync(..., TimeSpan.Zero, ...).
src/​Azure/​Orleans.Streaming.AzureStorage/​Providers/​Streams/​AzureQueue/​AzureQueueAdapterReceiver.cs Adds operation tracking and shutdown-time release of pending receipts; retains pending receipts until deletion confirms.
src/​Azure/​Orleans.Streaming.AzureStorage/​Orleans.Streaming.AzureStorage.csproj Adds InternalsVisibleTo for Orleans.Azure.Tests to enable internal test seams.
docs/​site/​src/​content/​docs/​implementation/​streams-implementation/​azure-queue-streams.md Documents graceful handoff behavior and the Azure Queue “Update Message” permission requirement.

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

@github-actions

github-actions Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request Current main Variance
Lines 81.12% (105,876 / 130,518) 81.17% (105,834 / 130,379) -0.0543 pp
Branches 69.82% (30,001 / 42,970) 69.86% (29,999 / 42,944) -0.0376 pp

Report-only conclusion: regressed.

The current-main baseline is commit 2e93596703 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 review requested due to automatic review settings September 5, 2026 09:08

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

It changes core receiver shutdown/acknowledgement behavior with concurrent operation tracking and message visibility updates, warranting final human validation despite the added tests.

Review tier: Lite
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity src/​Azure/​Orleans.Streaming.AzureStorage/​Providers/​Streams/​AzureQueue/​AzureQueueAdapterReceiver.cs — The shutdown-path receive bookkeeping removes duplicates by scanning pending once per newly…
Issues resolved since last review (1)
Severity Finding
High severity src/​Azure/​Orleans.Streaming.AzureStorage/​Providers/​Streams/​AzureQueue/​AzureQueueAdapterReceiver.cs — When shutdown begins during a receive, this branch clears pendingDeliveries, which later triggers… View resolved comment

Copilot AI review requested due to automatic review settings September 5, 2026 09:15

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

It changes shutdown/concurrency semantics in a production streaming receiver and relies on nuanced timing/cancellation behavior which warrants final human review despite the added tests.

Review tier: Lite
Findings: 1 Medium severity

Pre-existing issues (1)
Severity Finding
Medium severity src/​Azure/​Orleans.Streaming.AzureStorage/​Providers/​Streams/​AzureQueue/​AzureQueueAdapterReceiver.cs — The shutdown-path receive bookkeeping removes duplicates by scanning pending once per newly… View comment

Copilot AI review requested due to automatic review settings September 5, 2026 09:25

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

Delivered-message deletion can partially succeed but still leave successfully deleted items in the pending set, causing incorrect pending bookkeeping and unnecessary shutdown release attempts/logging.

Review tier: Lite
Findings: None

Issues resolved since last review (1)
Severity Finding
Medium severity src/​Azure/​Orleans.Streaming.AzureStorage/​Providers/​Streams/​AzureQueue/​AzureQueueAdapterReceiver.cs — The shutdown-path receive bookkeeping removes duplicates by scanning pending once per newly… View resolved comment
Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

src/Azure/Orleans.Streaming.AzureStorage/Providers/Streams/AzureQueue/AzureQueueAdapterReceiver.cs:298

  • ConfirmMessagesDeliveredAsync uses Task.WhenAll(...) and only removes items from pending after all deletes succeed. If one delete throws, successfully deleted messages remain in pending, causing unnecessary later release attempts/logging and preventing the receiver from accurately reflecting confirmed acknowledgements. Consider deleting each message independently, removing successfully deleted items from pending, and rethrowing an aggregate for the failures.

Copilot AI review requested due to automatic review settings September 5, 2026 14: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 review overview

🟡 Changes recommended

The new tests include an obsolete API call which can fail builds under warnings-as-errors and an order-dependent assertion which can introduce test flakiness.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 1 High severity · 1 Medium severity

New issues introduced by this change (2)
Severity Finding
High severity test/​Extensions/​Orleans.Azure.Tests/​Streaming/​AzureQueueAdapterTests.cs — This test calls the obsolete IQueueAdapterFactory.CreateAdapter() overload, which will raise…
Medium severity test/​Extensions/​Orleans.Azure.Tests/​Streaming/​AzureQueueAdapterReceiverTests.cs — This assertion depends on a specific ordering of queue.DeletedMessages/queue.ReleasedMessages,…

Copilot AI review requested due to automatic review settings September 5, 2026 14:32

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

It changes shutdown/handoff semantics in a distributed streaming receiver (including concurrent operation tracking and message visibility updates), which has significant reliability implications that warrant final human validation.

Review tier: Lite
Findings: None

Issues resolved since last review (2)
Severity Finding
Medium severity test/​Extensions/​Orleans.Azure.Tests/​Streaming/​AzureQueueAdapterReceiverTests.cs — This assertion depends on a specific ordering of queue.DeletedMessages/queue.ReleasedMessages,… View resolved comment
High severity test/​Extensions/​Orleans.Azure.Tests/​Streaming/​AzureQueueAdapterTests.cs — This test calls the obsolete IQueueAdapterFactory.CreateAdapter() overload, which will raise… View resolved comment

@ReubenBond
ReubenBond merged commit 575e2c6 into dotnet:main Sep 5, 2026
71 checks passed
@ReubenBond
ReubenBond deleted the rb-issue-11119-fix-azure-queue-delivery branch September 5, 2026 15:01
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 Azure Queue streaming test times out after 9 of 10 deliveries

2 participants