-
Notifications
You must be signed in to change notification settings - Fork 7
fix: Prevent race condition on updateContext #84
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
Conversation
Summary of ChangesHello @fabriziodemaria, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical race condition identified in the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
00b8ef0 to
ec5f9a4
Compare
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.
Code Review
This pull request addresses a race condition in updateContext by introducing an AsyncSerialQueue actor to serialize concurrent updates. The approach is sound and effectively resolves the reported crash. A new test case has been added to verify the fix by simulating concurrent access, which is great.
My review includes two main points:
- A suggestion to make the new concurrency test more robust by asserting the final state, rather than just checking for a crash.
- A more critical concern about a remaining race condition. The introduction of
contextUpdateQueuecreates a second synchronization mechanism alongside the existingDispatchQueue. This can lead to data races on shared state (likeevaluationContext) between methods synchronized differently, such asupdateContextandsetProvider. I've detailed this in a comment and recommend unifying the synchronization strategy for theOpenFeatureAPIclass.
Overall, this is a good fix for the immediate problem, but the underlying concurrency management of the OpenFeatureAPI class needs a more holistic review to ensure thread safety.
2a0aad0 to
8cc95c9
Compare
Suggestion to improve the performance from #84. In this PR, the queue to process state updates is "LastWins" policy and prevents execution of unnecessary intermediate states in the case of rapid calls to `setEvaluationContext`, for example Signed-off-by: Fabrizio Demaria <fabrizio.f.demaria@gmail.com>
4f28a6e to
8cc95c9
Compare
This PR wants to merge in #84, to improve the performance of the updateContext queue and avoid queue build-up by coalescing pending tasks and ensure last-one-wins operations. It might be a better alternative to #85: the latter was causing coalesced tasks to return immediately instead of waiting for the latest task to complete successfully, which in turn would make `setEvaluationContext` return before the context is actually updated and ready. --------- Signed-off-by: Fabrizio Demaria <fabrizio.f.demaria@gmail.com>
6543749 to
e830514
Compare
022342d to
f60414f
Compare
2b60e5c to
b639487
Compare
| stateQueue.sync { | ||
| self.providerSubject.send(nil) | ||
| self.providerStatus = .notReady | ||
| } | ||
| } |
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.
I think it's good to follow the same pattern used in setProvider here, although the fire-and-forget strategy of this API is IMO harder to reason around.
I added a clearProviderAndWait API that is integrates much better with the other *AndWait APIs and follows the FIFO ordering.
cdc6207 to
e4fd044
Compare
e4fd044 to
ff3b459
Compare
Signed-off-by: Fabrizio Demaria <fabrizio.f.demaria@gmail.com>
Signed-off-by: Fabrizio Demaria <fabrizio.f.demaria@gmail.com>
Signed-off-by: Fabrizio Demaria <fabrizio.f.demaria@gmail.com>
Signed-off-by: Fabrizio Demaria <fabrizio.f.demaria@gmail.com>
Signed-off-by: Fabrizio Demaria <fabrizio.f.demaria@gmail.com>
ff3b459 to
3f49bbe
Compare
Signed-off-by: Fabrizio Demaria <fabrizio.f.demaria@gmail.com>
efd2bd0 to
97925df
Compare
🤖 I have created a release *beep* *boop* --- ## [0.5.0](0.4.0...0.5.0) (2025-11-12) ### ⚠ BREAKING CHANGES * add provider event details ([#77](#77)) ### 🐛 Bug Fixes * Prevent race condition on updateContext ([#84](#84)) ([dd23929](dd23929)) ### ✨ New Features * add multiprovider ([#78](#78)) ([869b90a](869b90a)) * add provider event details ([#77](#77)) ([56b477e](56b477e)) * add Tracking API ([#81](#81)) ([c14b0cd](c14b0cd)) * Allow FlagEvaluationDetails to be a public API ([#79](#79)) ([0b07a8f](0b07a8f)) ### 📚 Documentation * Update docs with ImmutableContext ([#72](#72)) ([28ccd3e](28ccd3e)) --- 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>
This PR
readycould be emitted when a context is set without any provider setclearProviderAndWaitto complement the same pattern in setProvider and setEvaluationContextNotes
Stacktrace for the original crash (from point 1 above):