fix: introduce thread-safe locks in EventBus handler operations#352
fix: introduce thread-safe locks in EventBus handler operations#352DebasmitaBose0 wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesEventBus Thread-Safety
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🧪 PR Test Results
Python 3.12 · commit 9738bb1 |
|
@DebasmitaBose0 please fix your pr's |
|
@DebasmitaBose0 pr is sitting past 1 week ??? |
|
@sreerevanth Sorry for the inconvenience caused....I am fixing this |
|
@sreerevanth PR has no conflicts |
|
@DebasmitaBose0 check the ci also please |
|
@DebasmitaBose0 its a simple ci lint issue in case u got stuck im here to help u out just ping me anywhere is fyn |
|
@DebasmitaBose0 do u wanna work on this or no ? |
|
@DebasmitaBose0 please check this |
|
hey @DebasmitaBose0 please fix the linting issues its been sitting for 3 weeks |
Summary
This PR introduces thread-safe synchronization to the
EventBusoperations to prevent data races and runtime errors in multi-threaded environments, resolving #134.Problem
In multi-threaded contexts, concurrent operations on the
EventBus(such as subscribing, unsubscribing, publishing events, or querying stats) can cause data races, inconsistent state updates, or concurrency-related runtime errors.Proposed Changes
self._thread_lock = threading.Lock()within theEventBusconstructor.with self._thread_lock.stats()method to count active subscribers directly usinglen(self._handlers)under the lock, rather than callingself.handler_count(). Sinceself._thread_lockis a standardLock(and not anRLock), callinghandler_count()(which acquires the lock again) from within another lock-acquired method would lead to a deadlock.Verification Results
Ran all tests in the repository and verified that they pass with zero issues:
tests/test_core.py(includingTestEventBustest cases) passed successfully.Closes #134
Summary by CodeRabbit
Release Notes