feat: Support provider initialization and shutdown - #28
Open
kinyoklion wants to merge 1 commit into
Open
Conversation
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Implements the OpenFeature provider lifecycle hooks so the OpenFeature SDK can reflect LaunchDarkly initialization failures and release resources.
Provider#init, which raises when the LaunchDarkly client did not initialize, so the OpenFeature SDK moves the provider toERRORinstead of reportingREADY.Provider#shutdown, which closes the LaunchDarkly client when the provider is replaced orOpenFeature::SDK.shutdownis called.Implementation details
Requirements
Related issues
Part of an audit of the LaunchDarkly OpenFeature providers against the current OpenFeature specification. Provider lifecycle (spec sections 2.4 / 1.7) was unimplemented here: initialization failures were invisible to the OpenFeature SDK, and shutting down the OpenFeature SDK leaked the LaunchDarkly client's connections and event processor.
Describe the solution you've provided
OpenFeature::SDK::Configurationcallsiniton providers that respond to it and dispatchesPROVIDER_READYon success, orPROVIDER_ERRORwheninitraises; it callsshutdownon providers that respond to it.initusesLDClient#initialized?and includes the data source state fromdata_source_status_providerin the raised error message for diagnosability.Describe alternatives you've considered
Deferring LaunchDarkly client construction to
init— rejected because it would change the meaning of the existing publicclientaccessor and the constructor'swait_for_secondsargument. Blocking insideiniton a data source status listener — rejected as redundant, since the constructor already waits, and later state changes are better delivered as provider events.Testing
bundle exec rake(RSpec + RuboCop) on Ruby 3.4: 57 examples, 0 failures; 12 files inspected, no offenses. Ruby 3.4 was used because the gemspec requires>= 3.4.@cursor review
Link to Devin session: https://app.devin.ai/sessions/0c452d209ec54b068ba120b4c92b8f6c
Requested by: @kinyoklion
Note
Overview
Implements OpenFeature provider lifecycle hooks so the SDK can surface LaunchDarkly init failures and release resources on teardown.
initruns after the constructor has already waited on the LD client; ifinitialized?is false, it raises with the data source state so OpenFeature reportsPROVIDER_ERRORinstead ofREADY.shutdowncalls@client.closewhen the provider is replaced or the SDK shuts down (a new provider instance is required afterward, matching the Java provider).Specs cover successful init, failed init, and shutdown closing the client.
Reviewed by Cursor Bugbot for commit f45d6c6. Bugbot is set up for automated code reviews on this repo. Configure here.