From 95c9a03b9c907ea6f96d20c5b7e0d391a5f8a628 Mon Sep 17 00:00:00 2001 From: Dmitry Novik Date: Sun, 27 Mar 2022 16:56:41 +0000 Subject: [PATCH] Handle corner case --- src/Common/OvercommitTracker.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Common/OvercommitTracker.cpp b/src/Common/OvercommitTracker.cpp index af0780c6e44..95dd9fb0ccc 100644 --- a/src/Common/OvercommitTracker.cpp +++ b/src/Common/OvercommitTracker.cpp @@ -55,6 +55,12 @@ bool OvercommitTracker::needToStopQuery(MemoryTracker * tracker, Int64 amount) { return freed_momory >= required_memory || cancelation_state == QueryCancelationState::NONE; }); + + // If query cancelation is still running, it's possible that other queries will reach + // hard limit and end up on waiting on condition variable. + // If so we need to specify that some part of freed memory is acquired at this moment. + if (!timeout && cancelation_state == QueryCancelationState::RUNNING) + freed_momory -= amount; if (timeout) LOG_DEBUG(getLogger(), "Need to stop query because reached waiting timeout"); else