Merge pull request #51931 from ClickHouse/better-current-thread-check

Fix segfault caused by `ThreadStatus`
This commit is contained in:
Alexey Milovidov 2023-07-08 02:15:53 +03:00 committed by GitHub
commit c61f0bca65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -199,13 +199,14 @@ ThreadStatus::~ThreadStatus()
if (deleter)
deleter();
chassert(!check_current_thread_on_destruction || current_thread == this);
/// Only change current_thread if it's currently being used by this ThreadStatus
/// For example, PushingToViews chain creates and deletes ThreadStatus instances while running in the main query thread
if (check_current_thread_on_destruction)
{
assert(current_thread == this);
if (current_thread == this)
current_thread = nullptr;
}
else if (check_current_thread_on_destruction)
LOG_ERROR(log, "current_thread contains invalid address");
}
void ThreadStatus::updatePerformanceCounters()