fix: Honor the cancellation token when waiting for initialization - #72
Open
kinyoklion wants to merge 3 commits into
Open
kinyoklion wants to merge 3 commits into
kinyoklion wants to merge 3 commits into
Conversation
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Contributor
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Contributor
|
@cursor review |
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ 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.
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

InitializeAsyncignored itsCancellationToken, so a caller that passed a token toSetProviderAsynccould not stop waiting for the LaunchDarkly client.InitializeAsyncwith anOperationCanceledExceptioninstead of waiting for the data sourceRequirements
Related issues
None.
Implementation details
The OpenFeature .NET SDK passes the token given to
Api.SetProviderAsync(provider, cancellationToken)throughProviderRepositoryintoFeatureProvider.InitializeAsync. The provider returned_initCompletion.Taskdirectly, so the token had no effect.Waiting now goes through a helper which, when the token can be canceled, races
_initCompletion.Taskagainst aTaskCompletionSourcecanceled by a token registration._initCompletionitself is untouched, so the provider still becomesREADY(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.0passes (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
InitializeAsyncnow honors theCancellationTokenpassed through OpenFeature (e.g. fromSetProviderAsync), so callers can stop waiting for the LaunchDarkly data source without blocking until ready or permanent failure.Waiting goes through
WaitForInitializationAsync, which races_initCompletionagainst token cancellation. Cancellation is per call:_initCompletionis unchanged, so the client can still finish initializing and other waiters are unaffected. A canceled wait completes withOperationCanceledException.StatusProvidergainsStartupWaitCanceled: 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 inEmitStatusEvent.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.