Skip to content

Commit 348dd3e

Browse files
Backport #73081 to 24.11: Fix possible overestimate memory tracking
1 parent e9126dc commit 348dd3e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Common/ThreadStatus.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@ size_t ThreadStatus::getNextPipelineProcessorIndex() const
216216

217217
ThreadStatus::~ThreadStatus()
218218
{
219-
flushUntrackedMemory();
220-
221219
/// It may cause segfault if query_context was destroyed, but was not detached
222220
auto query_context_ptr = query_context.lock();
223221
assert((!query_context_ptr && getQueryId().empty()) || (query_context_ptr && getQueryId() == query_context_ptr->getCurrentQueryId()));
@@ -228,6 +226,9 @@ ThreadStatus::~ThreadStatus()
228226

229227
chassert(!check_current_thread_on_destruction || current_thread == this);
230228

229+
/// Flush untracked_memory **right before** switching the current_thread to avoid losing untracked_memory in deleter (detachFromGroup)
230+
flushUntrackedMemory();
231+
231232
/// Only change current_thread if it's currently being used by this ThreadStatus
232233
/// For example, PushingToViews chain creates and deletes ThreadStatus instances while running in the main query thread
233234
if (current_thread == this)

0 commit comments

Comments
 (0)