Skip to content

Commit

Permalink
fix: the limit-conn plugin cannot effectively intercept requests in s…
Browse files Browse the repository at this point in the history
…pecial scenarios (#4585)

Signed-off-by: spacewander <[email protected]>
Co-authored-by: spacewander <[email protected]>
  • Loading branch information
zuiyangqingzhou and spacewander authored Jul 16, 2021
1 parent 36adb11 commit 554a30e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions apisix/plugins/limit-conn/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function _M.decrease(conf, ctx)
end

core.tablepool.release("plugin#limit-conn", limit_conn)
ctx.limit_conn = nil
return
end

Expand Down
71 changes: 71 additions & 0 deletions t/plugin/limit-conn2.t
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 554a30e

Please sign in to comment.