Copilot commented on code in PR #3487:
URL: https://github.com/apache/brpc/pull/3487#discussion_r3849162956
##########
src/bvar/detail/sampler.cpp:
##########
@@ -211,9 +223,51 @@ void Sampler::schedule() {
}
void Sampler::destroy() {
- _mutex.lock();
- _used = false;
- _mutex.unlock();
+ int nborrow = 0;
+ std::string owner = _debug_name.empty() ? "An unnamed bvar" : "bvar";
+ {
+ BAIDU_SCOPED_LOCK(_mutex);
Review Comment:
`Sampler::destroy()` reads `_debug_name` outside `_mutex`
(`_debug_name.empty()`), but `_debug_name` is mutated under the same mutex in
`set_debug_name()`. This creates a data race and can also produce inconsistent
diagnostics. Build `owner` (or capture `_debug_name`) while holding `_mutex`,
then log using the captured value after unlocking.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]