Skip to content

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

Merged
skyerus merged 4 commits into
open-feature:mainfrom
skyerus:issue-90_singleton-locks
Oct 11, 2022
Merged

fix: locks on singleton and client state to ensure thread safety#93
skyerus merged 4 commits into
open-feature:mainfrom
skyerus:issue-90_singleton-locks

Conversation

@skyerus

@skyerus skyerus commented Oct 6, 2022

Copy link
Copy Markdown
Contributor

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

codecov-commenter commented Oct 6, 2022

Copy link
Copy Markdown

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

Comment thread pkg/openfeature/client.go Outdated
@skyerus skyerus force-pushed the issue-90_singleton-locks branch from 40af78d to c2c10a3 Compare October 7, 2022 14:21
Comment thread pkg/openfeature/client.go
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
Comment thread pkg/openfeature/client_test.go
Signed-off-by: Skye Gill <gill.skye95@gmail.com>

@toddbaert toddbaert left a comment

Copy link
Copy Markdown
Member

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