From 7b88c956c83f1aa5a9ae94edfc9f44627fd60c1e Mon Sep 17 00:00:00 2001 From: liyang830 Date: Fri, 12 Nov 2021 18:22:55 +0800 Subject: [PATCH] fix: quota limit was not reached, but the limit was exceeded --- src/Access/EnabledQuota.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Access/EnabledQuota.cpp b/src/Access/EnabledQuota.cpp index d776b2b851a..cf78bfd0475 100644 --- a/src/Access/EnabledQuota.cpp +++ b/src/Access/EnabledQuota.cpp @@ -52,9 +52,7 @@ struct EnabledQuota::Impl return end; } - /// We reset counters only if the interval's end has been calculated before. - /// If it hasn't we just calculate the interval's end for the first time and don't reset counters yet. - bool need_reset_counters = (end_loaded.count() != 0); + bool need_reset_counters = false; do { @@ -66,7 +64,12 @@ struct EnabledQuota::Impl UInt64 n = static_cast((current_time - end + duration) / duration); end = end + duration * n; if (end_of_interval.compare_exchange_strong(end_loaded, end.time_since_epoch())) + { + /// We reset counters only if the interval's end has been calculated before. + /// If it hasn't we just calculate the interval's end for the first time and don't reset counters yet. + need_reset_counters = true; break; + } end = std::chrono::system_clock::time_point{end_loaded}; } while (current_time >= end);