nic-6443 commented on code in PR #14015:
URL: https://github.com/apache/apisix/pull/14015#discussion_r4216545248
##########
apisix/plugins/limit-count/delayed-syncer.lua:
##########
@@ -340,15 +340,21 @@ local function sync_key(self, key)
core.log.error("get local delta from shm failed: ", err)
end
- if delta then
+ -- the key expires two windows after its creation and is not renewed, so a
+ -- node that only rejects loses it; flush anyway, otherwise that node keeps
+ -- judging on the same cached quota until the quota itself expires
+ if not err then
+ local had_delta = delta ~= nil
Review Comment:
Confirmed. After the entry expires, a successful zero-delta refresh goes
through `sync_to_shm`, and its `incr(key, -0, 0, ttl)` recreates the entry as
0. If Redis then fails, `had_delta` is true and the fallback is charged its
minimum of 1, which `sync_to_shm` then subtracts again, leaving -1. TEST 5–6 in
the .t reproduce it: the fallback count goes from 0 to 1.
I fixed it at the source instead of tightening the fallback condition:
`sync_to_shm` no longer touches the local delta entry when nothing was flushed
(790d368ce). An entry that already exists with 0 still follows the existing
path unchanged. With the fix, TEST 6 keeps the count at 0.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]