This is an automated email from the ASF dual-hosted git repository.

tokers 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 554a30e  fix: the limit-conn plugin cannot effectively intercept 
requests in special scenarios (#4585)
554a30e is described below

commit 554a30e64d09f32b17f99e5d91b13fa22dbc5a85
Author: jackfu <[email protected]>
AuthorDate: Fri Jul 16 11:48:36 2021 +0800

    fix: the limit-conn plugin cannot effectively intercept requests in special 
scenarios (#4585)
    
    Signed-off-by: spacewander <[email protected]>
    Co-authored-by: spacewander <[email protected]>
---
 apisix/plugins/limit-conn/init.lua |  1 +
 t/plugin/limit-conn2.t             | 71 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+)

diff --git a/apisix/plugins/limit-conn/init.lua 
b/apisix/plugins/limit-conn/init.lua
index d2935c2..e462f1d 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 565a5c7..c1d8f06 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

Reply via email to