Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Human confirmation is needed because correctness depends on runtime scheduling and TSAN coverage across supported architectures.
No open issues 🎉
What changed in this PR
This PR fixes data races during server startup by synchronizing completion and shutdown handoff for temporary bthreads used by bthread_init_fn. It also adds a regression test covering the initialization, startup, stop, and join sequence.
Changes:
- Makes
doneandstopatomic with appropriate release/acquire ordering. - Publishes the initialization callback result before startup proceeds.
- Adds a controlled regression test for the bthread initialization handoff.
| File | Description |
|---|---|
| test/brpc_server_unittest.cpp | Adds a regression test covering synchronized bthread initialization, startup, stop, and join sequencing. |
| src/brpc/server.cpp | Uses atomic completion and stop signaling to synchronize temporary initialization bthreads with server startup. |
Review effort: Lite
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:
Server::StartInternal()creates temporary bthreads to runServerOptions::bthread_init_fn.The initialization bthread writes
BthreadInitArgs::doneand repeatedly readsBthreadInitArgs::stop, while the startup thread readsdoneand writesstop. These fields were ordinarybools, so the concurrent accesses formedC++ data races. In particular, observing completion did not safely publish the
init callback result, and the init bthread was not synchronized with the
shutdown request.
What is changed and the side effects?
Changed:
BthreadInitArgs::doneandstopatomic.result.startup, stop, and join handoff.
The new test reports the original race under TSAN on the unmodified code. The
targeted
BthreadInitEntry/StartInternalreport disappears after thischange.
Side effects:
Performance effects:
This affects only temporary server-startup bthreads. It adds atomic accesses
to their completion and stop polling paths, not RPC request processing.
Breaking backward compatibility:
None.
Check List: