Skip to content
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

fix: locks on singleton and client state to ensure thread safety #93

Merged
merged 4 commits into from
Oct 11, 2022

Conversation

skyerus
Copy link
Contributor

@skyerus skyerus commented Oct 6, 2022

This PR

  • locks on singleton and client state to ensure thread safety

This PR adds multi-read/single-write locks to both the global singleton and the client. Particularly it addresses problems relating to the providers/hooks being mutated while an evaluation is occurring. This is especially important since some providers have provider hooks, and if we don't lock, it's possible hooks from provider1 run on provider2 if an interleaving thread switched the provider.

I've opted for the approach of locking a provider and its hooks to an evaluation transaction. Another thread is free to set a new provider but any ongoing transactions will carry on using the existing provider and its hooks.

Related Issues

Fixes #90

Notes

Follow-up Tasks

How to test

@codecov-commenter
Copy link

codecov-commenter commented Oct 6, 2022

Codecov Report

Merging #93 (72d021e) into main (524b054) will increase coverage by 2.83%.
The diff coverage is 97.64%.

@@            Coverage Diff             @@
##             main      #93      +/-   ##
==========================================
+ Coverage   70.21%   73.04%   +2.83%     
==========================================
  Files           8        8              
  Lines         601      653      +52     
==========================================
+ Hits          422      477      +55     
+ Misses        162      159       -3     
  Partials       17       17              
Impacted Files Coverage Δ
pkg/openfeature/client.go 73.02% <96.96%> (+3.38%) ⬆️
pkg/openfeature/openfeature.go 92.59% <100.00%> (+1.89%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@skyerus skyerus force-pushed the issue-90_singleton-locks branch from 40af78d to c2c10a3 Compare October 7, 2022 14:21
Signed-off-by: Skye Gill <gill.skye95@gmail.com>
Signed-off-by: Skye Gill <gill.skye95@gmail.com>
Signed-off-by: Skye Gill <gill.skye95@gmail.com>
@skyerus skyerus force-pushed the issue-90_singleton-locks branch from 6d76407 to 06ac26c Compare October 11, 2022 09:29
Signed-off-by: Skye Gill <gill.skye95@gmail.com>
Copy link
Member

@toddbaert toddbaert left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks as always @skyerus

@skyerus skyerus merged commit 9dbd6b0 into open-feature:main Oct 11, 2022
@skyerus skyerus deleted the issue-90_singleton-locks branch October 11, 2022 16:39
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.

[FEATURE] Ensure thread safety of sdk
5 participants