This is an automated email from the ASF dual-hosted git repository. spacewander pushed a commit to branch release/2.15 in repository https://gitbox.apache.org/repos/asf/apisix.git
commit 55082f6de4ee1a06db3ff9cfa8b8decd4af1ba43 Author: 罗泽轩 <[email protected]> AuthorDate: Wed Aug 24 11:11:47 2022 +0800 fix(limit-count): different route with same conf should not share counter (#7750) fix #7746 --- apisix/plugins/limit-count.lua | 2 +- t/plugin/limit-count3.t | 61 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/apisix/plugins/limit-count.lua b/apisix/plugins/limit-count.lua index e191b6223..56ff34cb2 100644 --- a/apisix/plugins/limit-count.lua +++ b/apisix/plugins/limit-count.lua @@ -251,7 +251,7 @@ function _M.access(conf, ctx) -- Here we use plugin-level conf version to prevent the counter from being resetting -- because of the change elsewhere. -- A route which reuses a previous route's ID will inherits its counter. - key = ctx.conf_type .. apisix_plugin.conf_version(conf) .. ':' .. key + key = ctx.conf_type .. ctx.conf_id .. ':' .. apisix_plugin.conf_version(conf) .. ':' .. key else key = conf.group .. ':' .. key end diff --git a/t/plugin/limit-count3.t b/t/plugin/limit-count3.t index 4298a20bd..0c5490616 100644 --- a/t/plugin/limit-count3.t +++ b/t/plugin/limit-count3.t @@ -224,3 +224,64 @@ passed } --- response_body [200,200] + + + +=== TEST 7: set another route with the same conf +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/2', + ngx.HTTP_PUT, + [[{ + "uri": "/hello1", + "plugins": { + "limit-count": { + "count": 2, + "time_window": 61 + } + }, + "upstream": { + "nodes": { + "127.0.0.1:1980": 1 + }, + "type": "roundrobin" + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- response_body +passed + + + +=== TEST 8: avoid sharing the same counter +--- config + location /t { + content_by_lua_block { + local json = require "t.toolkit.json" + local http = require "resty.http" + local uri = "http://127.0.0.1:" .. ngx.var.server_port + .. "/hello1" + local ress = {} + for i = 1, 2 do + local httpc = http.new() + local res, err = httpc:request_uri(uri) + if not res then + ngx.say(err) + return + end + table.insert(ress, res.status) + end + ngx.say(json.encode(ress)) + } + } +--- response_body +[200,200]
