Repository navigation
fix(runtime): honor membership and load cancellation lifetimes - #11237
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
There is a build-blocking compile issue in IMembershipGossiper.cs due to a missing System.Threading import for CancellationToken.
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/Orleans.Runtime/MembershipService/IMembershipGossiper.cs — IMembershipGossiper is missing System.Threading import |
What changed in this PR
This PR tightens cancellation/lifetime handling across Orleans runtime membership and deployment-load publishing paths so caller-provided tokens are honored (without unintentionally canceling shared/background operations) and shutdown/stop sequences preserve required functionality.
Changes:
- Propagate cancellation tokens through membership operations (refresh, gossip, probes, suspect/kill processing) with bounded waits while ensuring late task faults remain observed.
- Update deployment-load publishing to use a grain timer (with timer lifetime tokens) and to snapshot subscriber lists so notification failures/unsubscribes don’t prevent delivery to remaining subscribers.
- Add a cancellable
RunOrQueueTask<TResult>scheduler overload and introduce focused regression tests for these ownership/cancellation boundaries.
| File | Description |
|---|---|
| test/Orleans.Core.Tests/Runtime/DeploymentLoadPublisherTests.cs | Adds regression tests for deployment-load publication cancellation, timers, and subscriber behavior. |
| test/Orleans.Core.Tests/Membership/MembershipTableManagerTests.cs | Updates existing tests and adds new coverage for refresh/update cancellation and shutdown/maintenance lifetimes. |
| test/Orleans.Core.Tests/Membership/MembershipGossiperTests.cs | Adds tests validating cancellation propagation for gossip/probe/indirect-probe RPCs. |
| test/Orleans.Core.Tests/Membership/MembershipAgentTests.cs | Adds shutdown/heartbeat-stop regressions to ensure terminal status publication uses live bounded tokens. |
| test/Orleans.Core.Tests/Membership/ClusterHealthMonitorTests.cs | Updates calls to pass cancellation tokens through updated membership APIs. |
| src/Orleans.Runtime/Scheduler/SchedulerExtensions.cs | Adds cancellable RunOrQueueTask<TResult> overload used by indirect probe paths. |
| src/Orleans.Runtime/Placement/DeploymentLoadPublisher.cs | Switches to grain timer publication, forwards cancellation, snapshots subscribers, and preserves initial publication behavior. |
| src/Orleans.Runtime/MembershipService/RemoteSiloProber.cs | Forwards caller cancellation directly into probe system-target calls. |
| src/Orleans.Runtime/MembershipService/MembershipTableManager.cs | Introduces distinct lifetimes (maintenance vs manager lifetime), adds bounded-wait wrappers, and settles suspect/kill acknowledgements on maintenance exit. |
| src/Orleans.Runtime/MembershipService/MembershipSystemTarget.cs | Threads cancellation through gossip/probe RPC entry points and bounds waits while observing late faults. |
| src/Orleans.Runtime/MembershipService/MembershipGossiper.cs | Extends gossip API to accept/validate cancellation tokens and forwards them. |
| src/Orleans.Runtime/MembershipService/MembershipAgent.cs | Ensures shutdown status publication uses bounded “cleanup” lifetime and avoids canceling terminal publication due to heartbeat cancellation. |
| src/Orleans.Runtime/MembershipService/IMembershipGossiper.cs | Updates the interface signature to accept cancellation tokens (but currently missing a required import). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It changes core runtime lifecycle and membership cancellation/timeout semantics across multiple subsystems, which warrants final human validation despite the added targeted tests.
Review tier: Lite
Findings: 1
Pre-existing issues (1)
| Severity | Finding |
|---|---|
src/Orleans.Runtime/MembershipService/IMembershipGossiper.cs — IMembershipGossiper is missing System.Threading import View comment |
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
The changes affect core cluster membership, probing, gossip, and shutdown lifetimes where subtle cancellation/timing regressions can have high operational impact and warrants final human verification.
Review tier: Lite
Findings: 1
Pre-existing issues (1)
| Severity | Finding |
|---|---|
src/Orleans.Runtime/MembershipService/IMembershipGossiper.cs — IMembershipGossiper is missing System.Threading import View comment |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Unresolved cleanup acknowledgment loss, stale generated API output, missing cleanup-token forwarding, and a path-restricted workflow condition require fixes.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Lite
Findings: 3
New issues introduced by this change (3)
| Severity | Finding |
|---|---|
src/Orleans.Runtime/MembershipService/MembershipTableManager.cs — Acknowledged cleanup requests can be dropped |
|
src/Orleans.Runtime/MembershipService/MembershipTableManager.cs — Retry requeue can discard cleanup acknowledgments |
|
src/Orleans.Core/SystemTargetInterfaces/IMembershipTable.cs — Regenerate and commit the Core API surface |
Pre-existing issues (1)
| Severity | Finding |
|---|---|
src/Orleans.Runtime/MembershipService/IMembershipGossiper.cs — IMembershipGossiper is missing System.Threading import View comment |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Five unresolved findings remain, including one critical cleanup-acknowledgment issue.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Lite
Findings: 4
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/Orleans.Runtime/MembershipService/MembershipTableManager.cs — Draining after channel completion can fault on a live token |
Pre-existing issues (4)
| Severity | Finding |
|---|---|
src/Orleans.Runtime/MembershipService/MembershipTableManager.cs — Retry requeue can discard cleanup acknowledgments View comment |
|
src/Orleans.Runtime/MembershipService/MembershipTableManager.cs — Acknowledged cleanup requests can be dropped View comment |
|
src/Orleans.Runtime/MembershipService/IMembershipGossiper.cs — IMembershipGossiper is missing System.Threading import View comment |
|
src/Orleans.Core/SystemTargetInterfaces/IMembershipTable.cs — Regenerate and commit the Core API surface View comment |
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Unresolved moderate findings remain across provider waits, lifecycle timeouts and cleanup, scheduler cancellation, and refresh coordination.
Review tier: Lite
Findings: None
Issues resolved since last review (1)
| Severity | Finding |
|---|---|
src/AdoNet/Shared/Storage/RelationalStorageExtensions.cs — The per-record callback receives a token but does not use it, so cancellation during enumeration… View resolved comment |
Previously missed findings (2)
In code that hasn't changed since last review
src/Orleans.Runtime/MembershipService/MembershipTableManager.cs:136
pendingRefreshis read and assigned without synchronization, butRefreshis reachable concurrently from periodic maintenance, membership RPC/gossip, health, and service paths. Two callers can both observe a null or completed value and start separateRefreshInternaloperations, causing duplicate backend reads/cleanup and allowing the later assignment to hide one task from subsequent callers. Guard single-flight task creation with synchronization (while keeping caller-specificWaitAsyncoutside the guard).
src/Orleans.Runtime/Scheduler/SchedulerExtensions.cs:69- After queuing this work item, the method awaits
workItem.Taskwithout applyingcancellationTokento that wait. If cancellation arrives while the target scheduler is busy or stopped, callers such asProbeRemoteSiloIndirectlyremain pending until the queued item runs (and may never complete); the token is only observed inside the queued delegate. Observe the work-item task and useWaitAsync(cancellationToken)for the caller's wait.
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Copilot review overview
Review tier: Lite
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/Cassandra/Orleans.Clustering.Cassandra/CassandraClusteringTable.cs — ReadRowAsync returns MembershipTableData, which is non-nullable here, so `if (existingRow is… |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Unresolved critical and moderate findings remain in cancellation, scheduling, proxy generation, refresh, and shutdown paths.
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 (4)
| Severity | Finding |
|---|---|
src/Orleans.CodeGenerator/ProxyGenerator.cs — Avoid matching a second Async suffix |
|
src/Orleans.Runtime/MembershipService/MembershipSystemTarget.cs — Probe waits on the non-cancelable scheduler overload |
|
src/Orleans.Runtime/Placement/DeploymentLoadPublisher.cs — Startup timer registration cannot cancel its queued wait |
|
src/Orleans.Runtime/Scheduler/SchedulerExtensions.cs — Queued scheduler waits ignore caller cancellation |
Issues resolved since last review (1)
| Severity | Finding |
|---|---|
src/Cassandra/Orleans.Clustering.Cassandra/CassandraClusteringTable.cs — ReadRowAsync returns MembershipTableData, which is non-nullable here, so `if (existingRow is… View resolved comment |
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Copilot review overview
Review tier: Lite
Findings: 3
New issues introduced by this change (4)
| Severity | Finding |
|---|---|
src/AWS/Orleans.Clustering.DynamoDB/Membership/DynamoDBMembershipTable.cs — Batch deletes are now awaited sequentially. This reduces throughput when deleting many membership… View comment |
|
src/AdoNet/Shared/Storage/RelationalStorage.cs — Using CancellationToken.None for Task.Run means pre-canceled operations will still queue work… View comment |
|
src/Azure/Orleans.Clustering.AzureStorage/OrleansSiloInstanceManager.cs — The large-batch delete path changed from parallel deletes (Task.WhenAll) to sequential awaits.… View comment |
|
src/Google/Orleans.Clustering.Firestore/FirestoreMembershipTable.cs — Cleanup now performs chunk deletions sequentially whereas Task.WhenAll(...) previously allowed… View comment |
Issues resolved since last review (4)
| Severity | Finding |
|---|---|
src/Orleans.Runtime/Scheduler/SchedulerExtensions.cs — Queued scheduler waits ignore caller cancellation View resolved comment |
|
src/Orleans.Runtime/Placement/DeploymentLoadPublisher.cs — Startup timer registration cannot cancel its queued wait View resolved comment |
|
src/Orleans.Runtime/MembershipService/MembershipSystemTarget.cs — Probe waits on the non-cancelable scheduler overload View resolved comment |
|
src/Orleans.CodeGenerator/ProxyGenerator.cs — Avoid matching a second Async suffix View resolved comment |
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Three moderate review findings remain unresolved.
Review tier: Lite
Findings: None
Issues resolved since last review (4)
| Severity | Finding |
|---|---|
src/Google/Orleans.Clustering.Firestore/FirestoreMembershipTable.cs — Cleanup now performs chunk deletions sequentially whereas Task.WhenAll(...) previously allowed… View resolved comment |
|
src/Azure/Orleans.Clustering.AzureStorage/OrleansSiloInstanceManager.cs — The large-batch delete path changed from parallel deletes (Task.WhenAll) to sequential awaits.… View resolved comment |
|
src/AdoNet/Shared/Storage/RelationalStorage.cs — Using CancellationToken.None for Task.Run means pre-canceled operations will still queue work… View resolved comment |
|
src/AWS/Orleans.Clustering.DynamoDB/Membership/DynamoDBMembershipTable.cs — Batch deletes are now awaited sequentially. This reduces throughput when deleting many membership… View resolved comment |
Previously missed findings (1)
In code that hasn't changed since last review
src/Orleans.Runtime/MembershipService/MembershipSystemTarget.cs:204
- This catch is reachable when the provider throws an OperationCanceledException carrying a linked or backend token: the preceding filter requires exact token equality, so caller cancellation can fall through here, be logged as a refresh failure, and complete the RPC successfully. Filter on
cancellationToken.IsCancellationRequestedinstead so caller cancellation is propagated regardless of which token the provider reports.
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Copilot review overview
Review tier: Lite
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/AWS/Orleans.Clustering.DynamoDB/Membership/DynamoDBMembershipTable.cs — The async lambda in the Select creates an extra state machine and an unnecessary double-await.… View comment |
| await Task.WhenAll(tasks); | ||
| // Capture synchronous cancellation as a task so every started batch remains owned by WhenAll. | ||
| await Task.WhenAll(toDelete.BatchIEnumerable(MAX_BATCH_SIZE) | ||
| .Select(async batch => await storage.DeleteEntriesAsync(this.options.TableName, batch, cancellationToken))); |



Problem
Membership and deployment-load operations have distinct caller, background, shared-refresh, and shutdown lifetimes. Several paths discarded caller tokens or coupled shutdown publication to already-canceled background work. Membership providers also exposed tokenless operations, limiting cancellation to caller-side waits.
Solution
Async-suffixed, cancellation-awareIMembershipTablemethods and mark the original tokenless methods obsolete. Preserve the original signatures and compatibility bridges; default implementations support external tokenless providers with cancellable waits and terminal fault observation.AsyncAPIs. Keep shared refreshes alive until manager disposal, observe them once at creation, and let callers cancel their own waits. Settle cleanup acknowledgments when queued work stops, is rejected, or is evicted from the bounded queue.Wire and provider compatibility
The new membership RPC methods claim the original operation aliases using the existing source generator. Original generated request types remain available for calls through obsolete tokenless methods. Cancellation travels separately from the unchanged application-argument payload. Each receiver and backend retain responsibility for how underlying work responds to cancellation; cancellation can race with a committed write.
The regenerated API surfaces accompany the implementation. Focused regressions exercise real generated membership proxies with current and baseline-style serializer metadata, including legacy and Async calls, identical application payloads, and invocation outcomes. Other regressions cover legacy/default/native provider behavior, completed-result preservation, caller/shared/background ownership, cleanup queue pressure, shutdown status ordering, client ownership, parallel-batch cancellation, and load publication. Provider-authoring guidance documents these guarantees.
Relationship
This is the first replacement slice from #10236, based on
mainat05ba80021d7c41e633d59f46844f2f9ba6d15c7d, expanded by review to migrate every membership provider. It can ship independently of dissemination and content-addressed manifest retrieval. Deployment-load mutation retains its existing scheduler-owned path and membership-oracle eligibility checks.Microsoft Reviewers: Open in CodeFlow