diff --git a/apisix/plugins/limit-conn/init.lua b/apisix/plugins/limit-conn/init.lua index d2935c273146..e462f1dc7a9d 100644 --- a/apisix/plugins/limit-conn/init.lua +++ b/apisix/plugins/limit-conn/init.lua @@ -100,6 +100,7 @@ function _M.decrease(conf, ctx) end core.tablepool.release("plugin#limit-conn", limit_conn) + ctx.limit_conn = nil return end diff --git a/t/plugin/limit-conn2.t b/t/plugin/limit-conn2.t index 565a5c73047e..c1d8f0683cd0 100644 --- a/t/plugin/limit-conn2.t +++ b/t/plugin/limit-conn2.t @@ -107,3 +107,74 @@ GET /mysleep?seconds=0.1 request latency is 0.1 --- response_body 0.1 + + + +=== TEST 3: set both global and route +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/global_rules/1', + ngx.HTTP_PUT, + [[{ + "plugins": { + "limit-conn": { + "conn": 1, + "burst": 0, + "default_conn_delay": 0.3, + "rejected_code": 503, + "key": "remote_addr" + } + } + }]] + ) + + if code >= 300 then + ngx.status = code + ngx.say(body) + return + end + + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "uri": "/hello", + "plugins": { + "limit-conn": { + "conn": 1, + "burst": 0, + "default_conn_delay": 0.3, + "rejected_code": 503, + "key": "remote_addr" + } + }, + "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 4: hit route +--- log_level: debug +--- request +GET /hello +--- grep_error_log eval +qr/request latency is/ +--- grep_error_log_out +request latency is +request latency is