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: Evaluate should not share EvaluationStack between calls #374

Merged
merged 4 commits into from
Apr 4, 2024

Conversation

cwaldren-ld
Copy link
Contributor

@cwaldren-ld cwaldren-ld commented Mar 11, 2024

Addresses #373.

@launchdarkly launchdarkly deleted a comment from shortcut-integration bot Mar 11, 2024
@cwaldren-ld cwaldren-ld changed the title fix: Evaluator::Evaluate should take EvaluationStack as dependency fix: Evaluator::Evaluate should not share EvaluationStack between calls Mar 11, 2024
@cwaldren-ld cwaldren-ld changed the title fix: Evaluator::Evaluate should not share EvaluationStack between calls fix: Evaluate should not share EvaluationStack between calls Mar 11, 2024
@cwaldren-ld cwaldren-ld force-pushed the cw/sc-235941/thread-safe-evaluation branch 2 times, most recently from da3fcc0 to 820e910 Compare March 11, 2024 18:01
@cwaldren-ld
Copy link
Contributor Author

cwaldren-ld commented Apr 3, 2024

There are additional thread-safety concerns I've discovered while testing this. Specifically, although we may be able to make the evaluator thread safe, we need to ensure the data system implementations are thread safe as well.

Specific notes:

  • DataSystem::Initialized() needs to to be thread safe
  • If lazy loading, refreshing needs to be thread safe (the readers are supposed to be by definition, but the expiration tracker needs to be)
  • If background sync, the memory store is already thread safe.

Still, this PR is an incremental improvement and can be merged independently.

@cwaldren-ld cwaldren-ld marked this pull request as ready for review April 3, 2024 23:08
@cwaldren-ld cwaldren-ld requested a review from a team April 3, 2024 23:08
@cwaldren-ld cwaldren-ld force-pushed the cw/sc-235941/thread-safe-evaluation branch from 820e910 to 410339a Compare April 3, 2024 23:09
@@ -246,3 +249,30 @@ TEST_F(EvaluatorTests, FlagWithExperimentTargetingMissingContext) {
ASSERT_EQ(*detail, Value(false));
ASSERT_EQ(detail.Reason(), EvaluationReason::Fallthrough(false));
}

TEST_F(EvaluatorTests, ThreadSafeEvaluation) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This type of test is what I've done in the past, and I'm not really sure of a better way to do it.

Basically spin up a bunch of threads and see if ASAN is triggered.

@cwaldren-ld cwaldren-ld requested a review from kinyoklion April 3, 2024 23:10
* @param event_scope The event scope used for recording prerequisite
* events.
*/
[[nodiscard]] EvaluationDetail<Value> Evaluate(
data_model::Flag const& flag,
Context const& context,
EvaluationStack& stack,
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason the public API needs to take a stack versus making one. Or are we re-using the public version internal to the evaluator as well?

Copy link
Member

Choose a reason for hiding this comment

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

We also may want to consider a more generic EvaluationState that contains the evaluation stack.

Eventually you have big segment status and big segment membership that persist the duration of an evaluation.

Copy link
Contributor Author

@cwaldren-ld cwaldren-ld Apr 4, 2024

Choose a reason for hiding this comment

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

Yes, we are using this in AllFlags. So we setup the stack object once, then run all the evaluations on it.

I think I did that because it felt bad to be constructing the stack over and over for each flag - but I didn't have any concrete data, so I'd be fine pushing it back into the Evaluator.

It'd be safer that way too, if the stack somehow got un-balanced by a failed evaluation.

@cwaldren-ld cwaldren-ld force-pushed the cw/sc-235941/thread-safe-evaluation branch from 410a8dd to b39c9af Compare April 4, 2024 20:09
@cwaldren-ld cwaldren-ld merged commit 7fd64ef into main Apr 4, 2024
20 checks passed
@cwaldren-ld cwaldren-ld deleted the cw/sc-235941/thread-safe-evaluation branch April 4, 2024 21:11
@github-actions github-actions bot mentioned this pull request Apr 4, 2024
cwaldren-ld pushed a commit that referenced this pull request Apr 4, 2024
🤖 I have created a release *beep* *boop*
---


<details><summary>launchdarkly-cpp-server: 3.3.5</summary>

##
[3.3.5](launchdarkly-cpp-server-v3.3.4...launchdarkly-cpp-server-v3.3.5)
(2024-04-04)


### Bug Fixes

* Evaluate should not share EvaluationStack between calls
([#374](#374))
([7fd64ef](7fd64ef))
</details>

<details><summary>launchdarkly-cpp-server-redis-source: 2.1.5</summary>

##
[2.1.5](launchdarkly-cpp-server-redis-source-v2.1.4...launchdarkly-cpp-server-redis-source-v2.1.5)
(2024-04-04)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * launchdarkly-cpp-server bumped from 3.3.4 to 3.3.5
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions github-actions bot mentioned this pull request May 13, 2024
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.

2 participants