Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the limit-conn plugin cannot effectively intercept requests in special scenarios #4585

Merged
merged 16 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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