Skip to content

Commit

Permalink
[fix](runtime_profile) fix race condition in to_thrift (#45047)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

Fix race condition in `RuntimeProfile::to_thrift()`.

```
#6  0x000055bce5a78bbf in std::__throw_length_error (__s=0x55bca1eb7880 <str> "vector::reserve") at ../../../../../libstdc++-v3/src/c++11/functexcept.cc:82
#7  0x000055bcafbbbc8f in std::vector<doris::TRuntimeProfileNode, std::allocator<doris::TRuntimeProfileNode> >::reserve (this=this@entry=0x7f2e69c39f48, __n=<optimized out>)
    at /var/local/ldb-toolchain/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/vector.tcc:70
#8  0x000055bcafbb6e34 in doris::RuntimeProfile::to_thrift (this=<optimized out>, nodes=0x7f2e69c39f48) at /root/doris/be/src/util/runtime_profile.cpp:577
#9  0x000055bcafbb7780 in doris::RuntimeProfile::to_thrift (this=<optimized out>, nodes=0x7f2e69c39f48) at /root/doris/be/src/util/runtime_profile.cpp:612
#10 0x000055bcafbb7780 in doris::RuntimeProfile::to_thrift (this=<optimized out>, nodes=0x7f2e69c39f48) at /root/doris/be/src/util/runtime_profile.cpp:612
#11 0x000055bcafbb7780 in doris::RuntimeProfile::to_thrift (this=<optimized out>, nodes=0x7f2e69c39f48) at /root/doris/be/src/util/runtime_profile.cpp:612
#12 0x000055bcaf32ee52 in doris::LoadChannel::_report_profile (this=this@entry=0x6150116fca80, response=response@entry=0x61201b768340)
```
  • Loading branch information
kaijchen authored Dec 6, 2024
1 parent 0f74869 commit 4512cb0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions be/src/util/runtime_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,6 @@ void RuntimeProfile::to_thrift(TRuntimeProfileTree* tree) {
}

void RuntimeProfile::to_thrift(std::vector<TRuntimeProfileNode>* nodes) {
nodes->reserve(nodes->size() + _children.size());

int index = nodes->size();
nodes->push_back(TRuntimeProfileNode());
TRuntimeProfileNode& node = (*nodes)[index];
Expand All @@ -602,10 +600,13 @@ void RuntimeProfile::to_thrift(std::vector<TRuntimeProfileNode>* nodes) {

ChildVector children;
{
// _children may be modified during to_thrift(),
// so we have to lock and copy _children to avoid race condition
std::lock_guard<std::mutex> l(_children_lock);
children = _children;
}
node.num_children = children.size();
nodes->reserve(nodes->size() + children.size());

for (int i = 0; i < children.size(); ++i) {
int child_idx = nodes->size();
Expand Down

0 comments on commit 4512cb0

Please sign in to comment.