From f15623141ede304c5de0111c1f7075caef1c74d9 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sat, 6 Aug 2022 20:46:42 +0200 Subject: [PATCH] Fix error --- src/Common/CurrentThread.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Common/CurrentThread.h b/src/Common/CurrentThread.h index 9548a927cfd..24c9dac844a 100644 --- a/src/Common/CurrentThread.h +++ b/src/Common/CurrentThread.h @@ -104,15 +104,24 @@ public: class ScopedAttach : private boost::noncopyable { + private: + bool attached = false; public: explicit ScopedAttach(const ThreadGroupStatusPtr & thread_group) { - CurrentThread::attachTo(thread_group); + if (!CurrentThread::getGroup()) + { + CurrentThread::attachToIfDetached(thread_group); + attached = true; + } } ~ScopedAttach() { - CurrentThread::detachQuery(); + if (attached) + { + CurrentThread::detachQuery(); + } } };