Repository navigation
fix(streaming): release SQS messages during handoff - #11062
Conversation
There was a problem hiding this comment.
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
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
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.
Code coverage
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 |
There was a problem hiding this comment.
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
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
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 |
|---|---|
src/AWS/Orleans.Streaming.SQS/Streams/SQSAdapterReceiver.cs — Shutdown(TimeSpan timeout) currently awaits an existing outstandingTask without honoring the… View resolved comment |
There was a problem hiding this comment.
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
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
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 |
|---|---|
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.
There was a problem hiding this comment.
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 |
|---|---|
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
MessagesDeliveredAsyncremoves entries frompendingbefore 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 byShutdown, leaving FIFO message groups blocked until the visibility timeout expires. Keep delivered entries inpendinguntilDeleteMessagescompletes successfully (remove them only after a successful delete; otherwise leave them so shutdown can release).
There was a problem hiding this comment.
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
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/AWS/Orleans.Streaming.SQS/Streams/SQSAdapterReceiver.cs — Shutdown assigns the release operation to the shared outstandingTask field and then awaits it… |
33bf6c9 to
9df7992
Compare
There was a problem hiding this comment.
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
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
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 |
|---|---|
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 |
9df7992 to
15ce9bd
Compare
There was a problem hiding this comment.
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
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
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 |
|---|---|
src/AWS/Orleans.Streaming.SQS/Storage/SQSStorage.cs — ReleaseMessages introduces an SQS ChangeMessageVisibilityBatch call, which requires additional… View resolved comment |
|
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 |
15ce9bd to
704470b
Compare
There was a problem hiding this comment.
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 |
|---|---|
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 |
704470b to
df65e2b
Compare
29c9936 to
a0bd674
Compare
There was a problem hiding this comment.
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

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