From e9812255467073563727b45ee9f70890e44005ed Mon Sep 17 00:00:00 2001 From: comeonkai <675922716@qq.com> Date: Wed, 29 Apr 2026 07:44:04 +0000 Subject: [PATCH] bugfix: fix currentAmount_ larger than expect when Acquire failed problem --- sdk/include/Type.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/include/Type.h b/sdk/include/Type.h index 92890c3..3ae7953 100644 --- a/sdk/include/Type.h +++ b/sdk/include/Type.h @@ -289,6 +289,8 @@ class MyRateLimiter : public RateLimiter { int64_t tokenIncreaseAmount = duration * rate_/1000; int64_t tokenAmountMax = tokenIncreaseAmount + currentAmount_; currentAmount_ = tokenAmountMax > capacity_ ? capacity_ : tokenAmountMax; + // 避免 Acquire 失败场景,因lastTokenGiven_未更新导致 currentAmount_ 重复添加令牌 + lastTokenGiven_ = currentTime; // 极端情况下,want > 总容量,直接放过 if (want > capacity_) { std::pair res(true, 0); @@ -300,7 +302,6 @@ class MyRateLimiter : public RateLimiter { std::pair res(false, timeToWait); return res; } - lastTokenGiven_ = std::chrono::steady_clock::now(); currentAmount_ = currentAmount_ - want; std::pair res(true, 0); return res;