You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2020/12/10 06:50:24 UTC
[apisix] branch master updated: bugfix: always necessary to save
the data of the limit concurrency,
and release the statistical status in the log phase. (#2465)
This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new a670ea2 bugfix: always necessary to save the data of the limit concurrency, and release the statistical status in the log phase. (#2465)
a670ea2 is described below
commit a670ea2f2e7fc25bf3e597573a97a04594cbfee0
Author: YuanSheng Wang <me...@gmail.com>
AuthorDate: Thu Dec 10 14:50:15 2020 +0800
bugfix: always necessary to save the data of the limit concurrency, and release the statistical status in the log phase. (#2465)
fix #2450
---
apisix/plugins/limit-conn.lua | 7 ++---
t/plugin/limit-conn.t | 68 +++++++++++++++++++++++++++++++++++++++----
2 files changed, 66 insertions(+), 9 deletions(-)
diff --git a/apisix/plugins/limit-conn.lua b/apisix/plugins/limit-conn.lua
index b255f07..0249116 100644
--- a/apisix/plugins/limit-conn.lua
+++ b/apisix/plugins/limit-conn.lua
@@ -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
@@ -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
diff --git a/t/plugin/limit-conn.t b/t/plugin/limit-conn.t
index 351d301..e9e963e 100644
--- a/t/plugin/limit-conn.t
+++ b/t/plugin/limit-conn.t
@@ -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
@@ -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 {
@@ -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
@@ -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]