-
Notifications
You must be signed in to change notification settings - Fork 0
fix: make openFeatureProvider an instance field instead of static #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The static field caused all DevCycleLocalClient instances to share the same DevCycleProvider, which is incorrect when clients have different configurations. This aligns with DevCycleCloudClient's implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a design issue where the openFeatureProvider field in DevCycleLocalClient was incorrectly declared as static, causing all client instances to share the same provider. The fix changes it to an instance field so each client has its own provider, and removes the now-unnecessary class-level synchronization.
Changes:
- Changed
openFeatureProviderfrom static to instance field inDevCycleLocalClient - Removed class-level synchronized block that was protecting the static field initialization
- Simplified the lazy initialization logic while maintaining the platform data setup
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/main/java/com/devcycle/sdk/server/local/api/DevCycleLocalClient.java
Show resolved
Hide resolved
Use volatile + double-checked locking to prevent race condition when multiple threads call getOpenFeatureProvider() concurrently.
Use synchronized method instead of volatile + double-checked locking. Set platform data on every call rather than only on first access.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fix static OpenFeatureProvider field in DevCycleLocalClient
Problem
DevCycleLocalClientused astaticfield foropenFeatureProvider, causing all client instances to share the same provider. This is incorrect when clients have different configurations.Solution
Changed
openFeatureProviderfrom a static field to an instance field, and added thread-safe lazy initialization.Changes
private static DevCycleProvider→private DevCycleProvider(instance field)synchronizedtogetOpenFeatureProvider()method for thread safetygetOpenFeatureProvider()to ensure correct SDK trackingThread Safety
The
synchronizedmethod ensures that only oneDevCycleProviderinstance is created per client, even when multiple threads callgetOpenFeatureProvider()concurrently.