Skip to content

fix(streaming): release SQS messages during handoff - #11062

Merged
ReubenBond merged 13 commits into
dotnet:mainfrom
ReubenBond:rb-fix-sqs-fifo-deliveries
Sep 5, 2026
Merged

ReubenBond merged 13 commits into
dotnet:mainfrom
ReubenBond:rb-fix-sqs-fifo-deliveries

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Fixes #11022.

Problem

When SQS queue ownership moves to another silo, the previous receiver can shut down with unconfirmed messages still hidden by the queue visibility timeout. FIFO queues then block later messages in each affected message group, so the new owner can observe zero deliveries until that timeout expires.

Solution

Release every pending SQS receipt during receiver shutdown by setting its visibility timeout to zero. Batch release requests follow SQS limits, process all chunks before reporting partial failures, and log failed entries. A focused FIFO regression holds visibility for 60 seconds and verifies that a replacement receiver receives the message during the handoff window.

Rationale

Queue handoff transfers delivery responsibility to the replacement receiver. Returning the previous owner's unconfirmed receipts immediately preserves at-least-once delivery while allowing the new owner to resume each FIFO message group without waiting for visibility expiration.

Microsoft Reviewers: Open in CodeFlow

Copilot AI lite review requested due to automatic review settings September 4, 2026 08:29

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

Receiver shutdown currently does not consistently honor the provided timeout budget (can block longer than intended), which can undermine timely queue handoff under load.

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

Review tier: Lite
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity src/​AWS/​Orleans.Streaming.SQS/​Streams/​SQSAdapterReceiver.cs — Shutdown(TimeSpan timeout) currently awaits an existing outstandingTask without honoring the…
What changed in this PR

This PR addresses SQS FIFO queue handoff stalls by ensuring pending (unconfirmed) SQS receipts are proactively released during receiver shutdown so that a replacement receiver can immediately resume deliveries without waiting for the visibility timeout to expire.

Changes:

  • Release pending SQS receipts on receiver shutdown via ChangeMessageVisibilityBatch(VisibilityTimeout=0) with batching and per-entry failure logging.
  • Add a FIFO regression test which sets a long visibility timeout and verifies redelivery across receiver handoff.
  • Ensure test cleanup deletes both standard and FIFO queues.
File Description
test/​Extensions/​Orleans.AWS.Tests/​Streaming/​SQSAdapterTests.cs Adds FIFO handoff regression test and cleans up FIFO queues during teardown.
src/​AWS/​Orleans.Streaming.SQS/​Streams/​SQSAdapterReceiver.cs Releases pending SQS messages during shutdown and logs failures.
src/​AWS/​Orleans.Streaming.SQS/​Storage/​SQSStorage.cs Implements batched “release” operation using ChangeMessageVisibilityBatchAsync and reuses receipt validation.

💡 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 4, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request
Lines 81.83% (106,635 / 130,320)
Branches 70.96% (30,433 / 42,888)

Report-only conclusion: current-main baseline stale.

The newest successful coverage run tested 857948d, not current main f60570c.

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 4, 2026 09:35

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

SQSAdapterReceiver.Shutdown can race with concurrent receive/delivery paths, leading to potential NullReferenceException or collection-modified failures during pending-message release.

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

Review tier: Lite
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity src/​AWS/​Orleans.Streaming.SQS/​Streams/​SQSAdapterReceiver.cs — Shutdown reads outstandingTask directly in both the null-check and the await expression, and…
Issues resolved since last review (1)
Severity Finding
Medium severity src/​AWS/​Orleans.Streaming.SQS/​Streams/​SQSAdapterReceiver.cs — Shutdown(TimeSpan timeout) currently awaits an existing outstandingTask without honoring the… View resolved comment

Copilot AI review requested due to automatic review settings September 4, 2026 11:37

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

Receiver shutdown can skip the pending-receipt release if an outstanding operation faults/times out, undermining the handoff fix and causing avoidable CI noise/flakiness.

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

Review tier: Lite
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity src/​AWS/​Orleans.Streaming.SQS/​Streams/​SQSAdapterReceiver.cs — If the existing outstandingTask faults or exceeds the shutdown timeout, WaitAsync will throw and…
Issues resolved since last review (1)
Severity Finding
Medium severity src/​AWS/​Orleans.Streaming.SQS/​Streams/​SQSAdapterReceiver.cs — Shutdown reads outstandingTask directly in both the null-check and the await expression, and… View resolved comment
Suppressed comments (1)

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

test/Extensions/Orleans.AWS.Tests/Streaming/SQSAdapterTests.cs:135

  • The new FIFO handoff regression waits only 10s for redelivery. With real SQS and shared CI environments, 10s can be tight and may introduce flakiness; increasing this to a larger (but still < VisibilityTimeoutSeconds) value would make the test more robust while still validating the handoff window behavior.

Copilot AI review requested due to automatic review settings September 4, 2026 12:20

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

Shutdown receipt release can still miss receipts which were removed from pending before delete completion, allowing FIFO groups to remain blocked if shutdown occurs during an in-flight delete.

Review tier: Lite
Findings: None

Issues resolved since last review (1)
Severity Finding
Medium severity src/​AWS/​Orleans.Streaming.SQS/​Streams/​SQSAdapterReceiver.cs — If the existing outstandingTask faults or exceeds the shutdown timeout, WaitAsync will throw and… View resolved comment
Suppressed comments (1)

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

src/AWS/Orleans.Streaming.SQS/Streams/SQSAdapterReceiver.cs:176

  • MessagesDeliveredAsync removes entries from pending before the delete is confirmed. If shutdown happens while the delete is still in-flight (or times out/faults), those receipts are no longer tracked and therefore won’t be released by Shutdown, leaving FIFO message groups blocked until the visibility timeout expires. Keep delivered entries in pending until DeleteMessages completes successfully (remove them only after a successful delete; otherwise leave them so shutdown can release).

Copilot AI review requested due to automatic review settings September 4, 2026 18:20

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

There is a confirmed shutdown-time concurrency hazard where the release task can be overwritten and later fault unobserved due to unsynchronized use of outstandingTask.

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

Review tier: Lite
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity src/​AWS/​Orleans.Streaming.SQS/​Streams/​SQSAdapterReceiver.cs — Shutdown assigns the release operation to the shared outstandingTask field and then awaits it…

@ReubenBond
ReubenBond force-pushed the rb-fix-sqs-fifo-deliveries branch from 33bf6c9 to 9df7992 Compare September 4, 2026 19:15
Copilot AI review requested due to automatic review settings September 4, 2026 19: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

🟡 Changes recommended

The new ChangeMessageVisibilityBatch dependency introduces additional IAM permission requirements which need to be reflected in the SQS streaming documentation to avoid production misconfiguration.

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

Review tier: Lite
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity src/​AWS/​Orleans.Streaming.SQS/​Storage/​SQSStorage.cs — ReleaseMessages introduces an SQS ChangeMessageVisibilityBatch call, which requires additional…
Issues resolved since last review (1)
Severity Finding
Medium severity src/​AWS/​Orleans.Streaming.SQS/​Streams/​SQSAdapterReceiver.cs — Shutdown assigns the release operation to the shared outstandingTask field and then awaits it… View resolved comment

Copilot AI review requested due to automatic review settings September 4, 2026 19:35
@ReubenBond
ReubenBond force-pushed the rb-fix-sqs-fifo-deliveries branch from 9df7992 to 15ce9bd Compare September 4, 2026 19:35

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

Shutdown can stop awaiting a timed-out outstandingTask without observing its later fault, potentially leading to unobserved task exceptions; the fix is small and localized.

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

Review tier: Lite
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity src/​AWS/​Orleans.Streaming.SQS/​Streams/​SQSAdapterReceiver.cs — If the shutdown wait for outstandingTask times out/cancels, the underlying task can continue…
Issues resolved since last review (2)
Severity Finding
Medium severity src/​AWS/​Orleans.Streaming.SQS/​Storage/​SQSStorage.cs — ReleaseMessages introduces an SQS ChangeMessageVisibilityBatch call, which requires additional… View resolved comment
Medium severity src/​AWS/​Orleans.Streaming.SQS/​Streams/​SQSAdapterReceiver.cs — Shutdown assigns the release operation to the shared outstandingTask field and then awaits it… View resolved comment

Copilot AI review requested due to automatic review settings September 4, 2026 20:09
@ReubenBond
ReubenBond force-pushed the rb-fix-sqs-fifo-deliveries branch from 15ce9bd to 704470b Compare September 4, 2026 20:09

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

🟢 Approval recommended

The shutdown handoff fix is implemented with bounded timeouts, synchronized pending tracking, supporting documentation updates, and a targeted FIFO regression test.

Review tier: Lite
Findings: None

Issues resolved since last review (1)
Severity Finding
Medium severity src/​AWS/​Orleans.Streaming.SQS/​Streams/​SQSAdapterReceiver.cs — If the shutdown wait for outstandingTask times out/cancels, the underlying task can continue… View resolved comment

Copilot AI review requested due to automatic review settings September 4, 2026 21:26
@ReubenBond
ReubenBond force-pushed the rb-fix-sqs-fifo-deliveries branch from 704470b to df65e2b Compare September 4, 2026 21:26
Copilot AI review requested due to automatic review settings September 5, 2026 03:32
@ReubenBond
ReubenBond force-pushed the rb-fix-sqs-fifo-deliveries branch from 29c9936 to a0bd674 Compare September 5, 2026 03: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 and delivery semantics in a production streaming provider with concurrency and external-service interactions, and should receive final human validation beyond automated review.

Review tier: Lite
Findings: None

@ReubenBond
ReubenBond merged commit 0c79cc9 into dotnet:main Sep 5, 2026
66 of 68 checks passed
@ReubenBond
ReubenBond deleted the rb-fix-sqs-fifo-deliveries branch September 5, 2026 03:52
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 5, 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 SQS FIFO many-producer stream test observes zero deliveries

2 participants