Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The regression test does not deterministically overlap the reader with Stop(), so it can miss the intended race and allow the prior unsafe implementation to pass.
1 open issue
What changed in this PR
This pull request fixes a data race in EventDispatcher shutdown handling by replacing the volatile stop flag with an atomic flag and applying release/acquire synchronization across shutdown, status checks, and epoll/kqueue event loops.
Changes:
- Replaces
_stopwithbutil::atomic<bool>. - Uses release stores and acquire loads for shutdown state.
- Adds lifecycle and concurrent
Running()/Stop()regression tests.
| File | Description |
|---|---|
| test/brpc_event_dispatcher_unittest.cpp | Adds dispatcher lifecycle and concurrent Running()/Stop() regression tests. |
| src/brpc/event_dispatcher.h | Declares the atomic shutdown state and includes atomic support. |
| src/brpc/event_dispatcher_kqueue.cpp | Synchronizes shutdown checks and state publication in the kqueue dispatcher. |
| src/brpc/event_dispatcher_epoll.cpp | Synchronizes shutdown checks and state publication in the epoll dispatcher. |
Review effort: Lite
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The shutdown state now uses atomic acquire/release synchronization across event-loop paths, with regression tests covering lifecycle and concurrent shutdown behavior.
No open issues 🎉
1 resolved since last review
Review effort: Lite
Contributor
Author
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What problem does this PR solve?
Issue Number: resolve
Problem Summary:
EventDispatcher::_stopis read byRun()andRunning()whileStop()writes it from another thread. The existing
volatile booldoes notprovide atomicity, so these accesses form a C++ data race.
What is changed and the side effects?
Changed:
_stopwithbutil::atomic<bool>._stoponly requests shutdown and does not publish other shared state.Running()returns false immediately afterStop(), beforeJoin()clears the thread ID.Stop()andRunning().pthread_join()provides completion synchronization.Side effects:
Performance effects:
Shutdown-state accesses are atomic with relaxed ordering.
Breaking backward compatibility:
None.
Check List: