Skip to content

Commit 4148baf

Browse files
Backport #73081 to 24.3: Fix possible overestimate memory tracking
1 parent e67c055 commit 4148baf

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

204204
ThreadStatus::~ThreadStatus()
205205
{
206-
flushUntrackedMemory();
207-
208206
/// It may cause segfault if query_context was destroyed, but was not detached
209207
auto query_context_ptr = query_context.lock();
210208
assert((!query_context_ptr && getQueryId().empty()) || (query_context_ptr && getQueryId() == query_context_ptr->getCurrentQueryId()));
@@ -215,6 +213,9 @@ ThreadStatus::~ThreadStatus()
215213

216214
chassert(!check_current_thread_on_destruction || current_thread == this);
217215

216+
/// Flush untracked_memory **right before** switching the current_thread to avoid losing untracked_memory in deleter (detachFromGroup)
217+
flushUntrackedMemory();
218+
218219
/// Only change current_thread if it's currently being used by this ThreadStatus
219220
/// For example, PushingToViews chain creates and deletes ThreadStatus instances while running in the main query thread
220221
if (current_thread == this)

0 commit comments

Comments
 (0)