Skip to content

fix(client): honor startup cancellation and release startup resources - #11604

Merged
ReubenBond merged 7 commits into
dotnet:mainfrom
ReubenBond:rb-client-startup-cancellation
Oct 28, 2026
Merged

ReubenBond merged 7 commits into
dotnet:mainfrom
ReubenBond:rb-client-startup-cancellation

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Fixes #11585.

Client startup now cancels initialization work instead of only cancelling its wait. Manifest initialization cancels and joins its owned background run before returning OperationCanceledException, propagates initialization failures, and keeps subsequent refreshes tied to client lifetime after startup succeeds. The runtime closes pending and established connections and stops callback/gateway timers when startup is cancelled.

Gateway discovery uses additive InitializeGatewayListProviderAsync(CancellationToken) and GetGatewaysAsync(CancellationToken) APIs. Built-in providers pass cancellation through their existing storage/SDK seams, including paginated reads and background gateway refreshes. Owned Cassandra sessions created during cancelled initialization are released; shared/borrowed clients and sessions retain their existing ownership.

Backward compatibility: all tokenless gateway methods and existing public storage-helper signatures remain available, with no new obsoletion. Default interface implementations preserve legacy provider dispatch, bound legacy waits, and observe eventual completion. Generated public API changes are additive; normal Release package validation against 10.4.0 passes without new compatibility suppressions.

Manifest RPC cancellation signals the runtime while independently bounding the provider's local wait, preserving application cancellation-acknowledgement policy and runtime ownership of RPC callbacks. Deterministic regressions cover pre-cancelled/in-flight/completed initialization, owned-run joining, acknowledgement policy, legacy-provider compatibility, SDK token forwarding, pagination, and resource ownership.

Microsoft Reviewers: Open in CodeFlow

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.

🟡 Changes recommended

Startup cancellation can still hang on an in-flight gateway refresh, and the required-service lookup breaks observer-drain tests because their fixture does not register GatewayManager.

2 open issues
What changed in this PR

Addresses #11585 by making Orleans client startup waits cancellation-aware and adding resource cleanup when startup is canceled before the client lifecycle begins.

Changes:

  • Observe cancellation during manifest initialization, gateway discovery, and retry decisions.
  • Preserve connection cancellation exceptions and clean up partially started client resources.
  • Add regression tests using explicit startup-phase barriers and bounded cleanup assertions.
File Description
test/​Orleans.Runtime.Tests/​ClientConnectionTests/​ClusterClientTests.cs Adds cancellation and connection-cleanup regression tests.
src/​Orleans.Core/​Runtime/​OutsideRuntimeClient.cs Adds canceled-start cleanup and cancellation-aware retry handling.
src/​Orleans.Core/​Messaging/​GatewayManager.cs Makes gateway initialization and discovery waits cancelable.
src/​Orleans.Core/​Messaging/​ClientMessageCenter.cs Preserves cancellation exceptions during initial connection establishment.
src/​Orleans.Core/​Manifest/​ClientClusterManifestProvider.cs Accepts a cancellation token for the initial manifest wait.

Review effort: Balanced

Comment thread src/Orleans.Core/Runtime/OutsideRuntimeClient.cs
Comment thread src/Orleans.Core/Runtime/OutsideRuntimeClient.cs Outdated
Copilot AI balanced review requested due to automatic review settings October 27, 2026 21: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.

🔵 Needs a closer look

Startup cancellation can still hang indefinitely because cleanup waits for an uncancelable periodic gateway lookup before signalling manifest shutdown.

1 open issue
1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 27, 2026 21:49

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.

🟢 Approval recommended

There are no active review issues blocking the client startup cancellation and resource-cleanup changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@ReubenBond
ReubenBond force-pushed the rb-client-startup-cancellation branch from 877a9bd to 496bbbe Compare October 28, 2026 01:14
Copilot AI balanced review requested due to automatic review settings October 28, 2026 01:14

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.

🟡 Changes recommended

A failed manifest initialization can cause a successful retry to hang startup without honoring cancellation, while a canceled retry-filter wait can leave later faults unobserved.

2 open issues

Review effort: Balanced

Comment thread src/Orleans.Core/Manifest/ClientClusterManifestProvider.cs Outdated
Comment thread src/Orleans.Core/Runtime/OutsideRuntimeClient.cs Outdated
Copilot AI balanced review requested due to automatic review settings October 28, 2026 01:38

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.

🔵 Needs a closer look

Human assessment is needed because cancellation can leave connection tasks unobserved, potentially surfacing exceptions after startup cleanup.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request Current main Variance
Lines 83.84% (121,009 / 144,338) 83.83% (120,850 / 144,155) +0.0039 pp
Branches 73.66% (36,271 / 49,238) 73.67% (36,263 / 49,222) -0.0077 pp

Report-only conclusion: mixed.

The current-main baseline is commit 30137dd94f 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

@ReubenBond
ReubenBond merged commit 8a95ab3 into dotnet:main Oct 28, 2026
95 checks passed
@ReubenBond
ReubenBond deleted the rb-client-startup-cancellation branch October 28, 2026 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cancelling a client's start has no effect while it waits for the cluster manifest

2 participants