fix: goroutine leaks in event executor and improve shutdown handling#472
fix: goroutine leaks in event executor and improve shutdown handling#472
Conversation
…tdown handling Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
Summary of ChangesHello @beeme1mr, 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 significantly improves the stability and resource management of the OpenFeature SDK by addressing potential goroutine leaks within the event executor. It introduces a robust shutdown mechanism that ensures all background event processing routines are properly terminated when no longer needed, and integrates a powerful leak detection tool to safeguard against future concurrency issues. These changes enhance the overall reliability of the SDK, particularly in long-running applications or scenarios involving frequent provider changes. Highlights
Changelog
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
|
There was a problem hiding this comment.
Code Review
This is an excellent pull request that addresses a critical issue of potential goroutine leaks in the event executor. The implementation of a graceful shutdown mechanism using standard concurrency primitives like sync.WaitGroup, sync.Once, and a done channel is well-executed and robust. The addition of go.uber.org/goleak and the comprehensive new tests that verify the absence of leaks are particularly commendable, as they significantly improve the reliability of the library. The refactoring of existing tests to prevent leaks and improve readability is also a great enhancement. I have one minor suggestion to make the channel draining logic in the shutdown method more idiomatic and robust.
| for len(e.eventChan) > 0 { | ||
| <-e.eventChan | ||
| } |
There was a problem hiding this comment.
While the current approach to draining the event channel is likely safe because all producer goroutines should have been stopped and waited for via e.wg.Wait(), using len(e.eventChan) in a loop can be racy if there are concurrent writers. A more robust and idiomatic way to drain a channel non-blockingly is to use a select with a default case. This ensures that the drain operation is safe even if future code changes inadvertently introduce a race condition.
for {
select {
case <-e.eventChan:
default:
return
}
}
This PR
Related Issues
Fixes #471
Notes
Added go.uber.org/goleak to try and detect other leaks.
How to test
Run test suite