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

Add setter for context #55

Merged
merged 1 commit into from
Sep 8, 2022
Merged

Add setter for context #55

merged 1 commit into from
Sep 8, 2022

Conversation

toddbaert
Copy link
Member

Adding this for consistency with other SDKs.

Signed-off-by: Todd Baert <toddbaert@gmail.com>
@codecov-commenter
Copy link

Codecov Report

Merging #55 (acce643) into main (01c0f34) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #55      +/-   ##
==========================================
+ Coverage   94.72%   94.73%   +0.01%     
==========================================
  Files          18       18              
  Lines         417      418       +1     
  Branches       33       33              
==========================================
+ Hits          395      396       +1     
  Misses         13       13              
  Partials        9        9              
Impacted Files Coverage Δ
src/OpenFeature.SDK/OpenFeatureClient.cs 99.21% <100.00%> (+<0.01%) ⬆️

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

/// <summary>
/// Sets the EvaluationContext of the client<see cref="EvaluationContext"/>
/// </summary>
public void SetContext(EvaluationContext evaluationContext) => this._evaluationContext = evaluationContext;
Copy link
Member

Choose a reason for hiding this comment

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

It isn't specifically related to this change, but is this code generally expected to be thread safe?

Copy link
Member Author

Choose a reason for hiding this comment

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

It isn't specifically related to this change, but is this code generally expected to be thread safe?

Hmm, there's nothing in the spec about it, but I think that we'd likely want the context in the client and the api singleton to be thread safe, so that we could have some predictability around it.

Are you thinking we should synchronize this method?

Copy link
Member

Choose a reason for hiding this comment

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

I've not looked through the code much yet with an eye for thread safety. Synchronizing set/get access to this method would affect which instance is being used during an evaluation when it was concurrently modified, which would make ordering a bit more predictable.

That said the context itself is mutable, so thread behavior around mutating the context itself is likely more problematic.

I suspect there are currently opportunities for concurrent modification exceptions to be thrown if the context, or contained structures, was being mutated while other things may be trying to enumerate

Probably doesn't need to mingle with this PR.

Copy link
Member Author

@toddbaert toddbaert Sep 8, 2022

Choose a reason for hiding this comment

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

I will add an issue to investigate thread safety overall in the this and the Java SDK.

I suspect that whatever thread safety issues exist here we also have in Java.

That said the context itself is mutable, so thread behavior around mutating the context itself is likely more problematic.

I think mutating the client and global context is not really something we want to encourage, they should be get/set wholesale. Context can be mutated in hooks, where each hook has it's own context and where I believe there's no thread safety concerns. I hope that makes sense. I'm not sure what kind of guardrails C# can add for us here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Created #56

@toddbaert toddbaert merged commit 2768d4c into main Sep 8, 2022
@kinyoklion kinyoklion deleted the client-setcontext branch September 8, 2022 18:28
@benjiro benjiro added the enhancement New feature or request label Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants