Skip to content

Commit ff07f31

Browse files
Backport #73081 to 24.8: Fix possible overestimate memory tracking
1 parent 67a16dd commit ff07f31

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
@@ -206,8 +206,6 @@ bool ThreadStatus::isQueryCanceled() const
206206

207207
ThreadStatus::~ThreadStatus()
208208
{
209-
flushUntrackedMemory();
210-
211209
/// It may cause segfault if query_context was destroyed, but was not detached
212210
auto query_context_ptr = query_context.lock();
213211
assert((!query_context_ptr && getQueryId().empty()) || (query_context_ptr && getQueryId() == query_context_ptr->getCurrentQueryId()));
@@ -218,6 +216,9 @@ ThreadStatus::~ThreadStatus()
218216

219217
chassert(!check_current_thread_on_destruction || current_thread == this);
220218

219+
/// Flush untracked_memory **right before** switching the current_thread to avoid losing untracked_memory in deleter (detachFromGroup)
220+
flushUntrackedMemory();
221+
221222
/// Only change current_thread if it's currently being used by this ThreadStatus
222223
/// For example, PushingToViews chain creates and deletes ThreadStatus instances while running in the main query thread
223224
if (current_thread == this)

0 commit comments

Comments
 (0)