Skip to content

Commit

Permalink
bugfix: always necessary to save the data of the limit concurrency, a…
Browse files Browse the repository at this point in the history
…nd release the statistical status in the log phase. (#2465)

fix #2450
  • Loading branch information
membphis authored Dec 10, 2020
1 parent 270aef0 commit a670ea2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 9 deletions.
7 changes: 3 additions & 4 deletions apisix/plugins/limit-conn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ end

function _M.access(conf, ctx)
core.log.info("ver: ", ctx.conf_version)
local lim, err = core.lrucache.plugin_ctx(lrucache, ctx, nil,
create_limit_obj, conf)
local lim, err = lrucache(conf, nil, create_limit_obj, conf)
if not lim then
core.log.error("failed to instantiate a resty.limit.conn object: ", err)
return 500
Expand All @@ -88,9 +87,9 @@ function _M.access(conf, ctx)
if lim:is_committed() then
if not ctx.limit_conn then
ctx.limit_conn = core.tablepool.fetch("plugin#limit-conn", 0, 6)
else
core.table.insert_tail(ctx.limit_conn, lim, key, delay)
end

core.table.insert_tail(ctx.limit_conn, lim, key, delay)
end

if delay >= 0.001 then
Expand Down
68 changes: 63 additions & 5 deletions t/plugin/limit-conn.t
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ done
=== TEST 26: create consumer and bind key-auth plugin
--- config
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
Expand Down Expand Up @@ -1019,7 +1019,7 @@ passed
=== TEST 27: create route and enable plugin 'key-auth'
=== TEST 27: create route and enable plugin 'key-auth'
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -1207,9 +1207,9 @@ qr/limit key: consumer_jackroute&consumer\d+/
content_by_lua_block {
local plugin = require("apisix.plugins.limit-conn")
local ok, err = plugin.check_schema({
conn = 1,
default_conn_delay = 0.1,
rejected_code = 503,
conn = 1,
default_conn_delay = 0.1,
rejected_code = 503,
key = 'consumer_name'
})
if not ok then
Expand All @@ -1225,3 +1225,61 @@ property "burst" is required
done
--- no_error_log
[error]
=== TEST 32: enable plugin: conn=1
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"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"
},
"uri": "/hello"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
=== TEST 33: hit route and should not be limited
--- pipelined_requests eval
[
"GET /hello", "GET /hello", "GET /hello",
"GET /hello", "GET /hello", "GET /hello",
]
--- timeout: 10s
--- error_code eval
[
200, 200, 200,
200, 200, 200
]
--- no_error_log
[error]

0 comments on commit a670ea2

Please sign in to comment.