Skip to content

fix: Honor the cancellation token when waiting for initialization - #72

Open
kinyoklion wants to merge 3 commits into
mainfrom
devin/1790174787-dotnet-init-cancellation
Open

kinyoklion wants to merge 3 commits into
mainfrom
devin/1790174787-dotnet-init-cancellation

Conversation

@kinyoklion

@kinyoklion kinyoklion commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

InitializeAsync ignored its CancellationToken, so a caller that passed a token to SetProviderAsync could not stop waiting for the LaunchDarkly client.

  • Cancelling the token now completes InitializeAsync with an OperationCanceledException instead of waiting for the data source
  • Cancellation is per-call: cancelling one wait leaves the provider initializing and does not fail other waiters
  • Feature matrix Initialization row updated to describe the behavior

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

None.

Implementation details

The OpenFeature .NET SDK passes the token given to Api.SetProviderAsync(provider, cancellationToken) through ProviderRepository into FeatureProvider.InitializeAsync. The provider returned _initCompletion.Task directly, so the token had no effect.

Waiting now goes through a helper which, when the token can be canceled, races _initCompletion.Task against a TaskCompletionSource canceled by a token registration. _initCompletion itself is untouched, so the provider still becomes READY (or errors) when the data source reports its state, regardless of a canceled wait.

Shutdown is unchanged: it only removes listeners and disposes the client, so there is no wait to cancel.

Tests: two cases covering cancellation of a first wait and of a wait on an already in-progress initialization. dotnet test -f net8.0 passes (70 tests).

Note: #71 also changes initialization waiting; whichever merges second needs a trivial rebase of this region.

Link to Devin session: https://app.devin.ai/sessions/a47abf28ecd44130917b9b5131287221
Open in Devin Desktop: https://app.devin.ai/desktop/session/a47abf28ecd44130917b9b5131287221?variant=devin
Requested by: @kinyoklion


Note

Overview
InitializeAsync now honors the CancellationToken passed through OpenFeature (e.g. from SetProviderAsync), so callers can stop waiting for the LaunchDarkly data source without blocking until ready or permanent failure.

Waiting goes through WaitForInitializationAsync, which races _initCompletion against token cancellation. Cancellation is per call: _initCompletion is unchanged, so the client can still finish initializing and other waiters are unaffected. A canceled wait completes with OperationCanceledException.

StatusProvider gains StartupWaitCanceled: it clears the “first event” suppression and, if status is already known, emits the matching provider event so subscribers still see READY (or stale/error) after a canceled startup wait. Status messages are retained for that replay; event emission is centralized in EmitStatusEvent.

The README Initialization row and three unit tests document and cover token cancel on first wait, cancel on a concurrent second wait, and ProviderReady after cancel when the data source later becomes valid.

Reviewed by Cursor Bugbot for commit afef99f. Bugbot is set up for automated code reviews on this repo. Configure here.

Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration

Copy link
Copy Markdown
Contributor

@cursor review

@kinyoklion
kinyoklion marked this pull request as ready for review September 29, 2026 22:42
@kinyoklion
kinyoklion requested a review from a team as a code owner September 29, 2026 22:42

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/LaunchDarkly.OpenFeature.ServerProvider/Provider.cs
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit fb037c7. Configure here.

Comment thread src/LaunchDarkly.OpenFeature.ServerProvider/Provider.cs
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant