Skip to content

Commit

Permalink
branch-3.0: [fix](runtime_profile) fix race condition in to_thrift #4…
Browse files Browse the repository at this point in the history
…5047 (#45098)

Cherry-picked from #45047

Co-authored-by: Kaijie Chen <[email protected]>
  • Loading branch information
github-actions[bot] and kaijchen authored Dec 6, 2024
1 parent d1c20c4 commit 3f3a9f4
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 @@ -577,8 +577,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 @@ -605,10 +603,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 3f3a9f4

Please sign in to comment.