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

bug: the limit-conn plugin has a bug #4556

Closed
zuiyangqingzhou opened this issue Jul 7, 2021 · 7 comments · Fixed by #4585
Closed

bug: the limit-conn plugin has a bug #4556

zuiyangqingzhou opened this issue Jul 7, 2021 · 7 comments · Fixed by #4585

Comments

@zuiyangqingzhou
Copy link
Contributor

Issue description

When the global limit-conn plug-in is enabled, and the limit-conn plug-in is also enabled on a specific route, the limit of the number of concurrent connections will be incorrect.

Environment

Bug report without environment information will be ignored or closed.

  • apisix version (cmd: apisix version): 2.6
  • OS (cmd: uname -a): Darwin bogon 20.5.0 Darwin Kernel Version 20.5.0
  • OpenResty / Nginx version (cmd: nginx -V or openresty -V): nginx version: openresty/1.19.3.2
  • etcd version, if have (cmd: run curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API): etcd Version: 3.4.16
  • apisix-dashboard version, if have: 2.7
  • luarocks version, if the issue is about installation (cmd: luarocks --version): /usr/local/bin/luarocks 3.7.0

Minimal test code / Steps to reproduce the issue

Bug report without steps to reproduce will be ignored or closed.

  1. set limit-conn on global_rule
curl http://127.0.0.1:9080/apisix/admin/global_rules/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "plugins": {
        "limit-conn": {
            "conn": 5,
            "burst": 0,
            "default_conn_delay": 0.1,
            "rejected_code": 501,
            "key": "http_x_forwarded_for"
        }
    }
}'
  1. set limit-conn on test router
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "methods": ["GET"],
    "uri": "/test",
    "plugins": {
        "limit-conn": {
            "conn": 3,
            "burst": 0,
            "default_conn_delay": 0.1,
            "rejected_code": 503,
            "key": "http_x_forwarded_for"
        }
    },
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "127.0.0.1:9999": 1
        }
    }
}'
  1. the back-end node logic is as follows
 package main

 import (
     "fmt"
     "log"
     "net/http"
     "os"
     "time"
 )
 func HelloServer(w http.ResponseWriter, req *http.Request) {
     time.Sleep(time.Second * 5)
     _, _ = fmt.Fprintln(w,"Header全部数据:",req.Header)
 }

 func main() {
     http.HandleFunc("/test", HelloServer)
     err := http.ListenAndServe(":9999", nil)
     if err != nil {
         log.Fatal("ListenAndServe: ", err)
     }
 }
  1. Because limit-conn will involve two phases, in order to identify that it belongs to one phase, I added a uuid as an identification, the code is as follows

zuiyangqingzhou@18d0023#diff-501e2c23c5fcf9e6df8c359429ef4b125e1a7e1abb593316f592df1b1024f97d

  1. batch send request
xargs -I % -P 10 curl -X GET "http://localhost:9080/test" < <(printf '%s\n' {1..20})

What's the actual result? (including assertion message & call stack if applicable)

Only three requests were intercepted, and the rest passed normally,

<html>
<head><title>503 Service Temporarily Unavailable</title></head>
<body>
<center><h1>503 Service Temporarily Unavailable</h1></center>
<hr><center>openresty</center>
</body>
</html>
<html>
<head><title>503 Service Temporarily Unavailable</title></head>
<body>
<center><h1>503 Service Temporarily Unavailable</h1></center>
<hr><center>openresty</center>
</body>
</html>
<html>
<head><title>503 Service Temporarily Unavailable</title></head>
<body>
<center><h1>503 Service Temporarily Unavailable</h1></center>
<hr><center>openresty</center>
</body>
</html>
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]
Header全部数据: map[Accept:[*/*] User-Agent:[curl/7.64.1] X-Forwarded-For:[127.0.0.1] X-Forwarded-Host:[localhost] X-Forwarded-Port:[9080] X-Forwarded-Proto:[http] X-Real-Ip:[127.0.0.1]]

The recorded log information is as follows

2021/07/07 17:47:48 [error] 57507#2086044: *642044 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 1, commit: true, uuid: 51d63d9a-262b-4def-b6a0-2e79a6ba022b, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642044 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 1, commit: true, uuid: b743e265-8e2b-4f85-8c4e-fcea94ada3af, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642053 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 2, commit: true, uuid: 338bab51-6761-4153-ac98-1f2a0af4482f, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642053 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 2, commit: true, uuid: 28b85b32-1917-425a-86c4-070836b88361, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642057 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 3, commit: true, uuid: db11b846-e587-4e98-9301-441890368101, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642057 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 3, commit: true, uuid: c1162fb6-50f0-4789-b2ed-593136b82421, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642059 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 4, commit: true, uuid: 632de10a-967f-4e48-8830-613621f2b1ed, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642059 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: nil, error: rejected, commit: false, uuid: 3d43841a-77f6-479a-95aa-db1acae19d0f, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [warn] 57507#2086044: *642059 [lua] plugin.lua:646: run_plugin(): limit-conn exits with http status code 503, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642059 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 3, error: nil, uuid: 51d63d9a-262b-4def-b6a0-2e79a6ba022b while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642059 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 2, error: nil, uuid: b743e265-8e2b-4f85-8c4e-fcea94ada3af while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642059 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 2, error: nil, uuid: 338bab51-6761-4153-ac98-1f2a0af4482f while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642059 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 1, error: nil, uuid: 28b85b32-1917-425a-86c4-070836b88361 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642059 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 1, error: nil, uuid: db11b846-e587-4e98-9301-441890368101 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642059 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 0, error: nil, uuid: c1162fb6-50f0-4789-b2ed-593136b82421 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642059 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 0, error: nil, uuid: 632de10a-967f-4e48-8830-613621f2b1ed while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642060 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 1, commit: true, uuid: c72122c5-0ce6-4a0d-beda-20f61a078b4d, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642060 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 1, commit: true, uuid: e7fe71e6-8ea2-4c3b-9372-3d83717eb573, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642061 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 2, commit: true, uuid: 26e4762f-887f-4d6a-962e-958dc0f3c701, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642061 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 2, commit: true, uuid: 0ac29141-6c43-41ed-a975-900bc30f5912, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642062 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 3, commit: true, uuid: 626e83c3-2f0a-4bd8-8ddd-42ec7fd40cf9, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642062 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 3, commit: true, uuid: 37e88be4-9ed7-48e9-9d34-c4dd5297797f, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642063 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 4, commit: true, uuid: 6d0ae820-0c1e-4680-b675-a0b57e3323b0, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642063 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: nil, error: rejected, commit: false, uuid: 65661c83-e97c-4313-a371-4864a9a7b46d, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [warn] 57507#2086044: *642063 [lua] plugin.lua:646: run_plugin(): limit-conn exits with http status code 503, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642063 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 3, error: nil, uuid: c72122c5-0ce6-4a0d-beda-20f61a078b4d while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642063 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 2, error: nil, uuid: e7fe71e6-8ea2-4c3b-9372-3d83717eb573 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642063 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 2, error: nil, uuid: 26e4762f-887f-4d6a-962e-958dc0f3c701 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642063 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 1, error: nil, uuid: 0ac29141-6c43-41ed-a975-900bc30f5912 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642063 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 1, error: nil, uuid: 626e83c3-2f0a-4bd8-8ddd-42ec7fd40cf9 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642063 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 0, error: nil, uuid: 37e88be4-9ed7-48e9-9d34-c4dd5297797f while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642063 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 0, error: nil, uuid: 6d0ae820-0c1e-4680-b675-a0b57e3323b0 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642064 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 1, commit: true, uuid: 3aeb7266-9c9e-4bbe-9a29-5e164e492339, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642064 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 1, commit: true, uuid: cfe7834a-fdc0-4f83-8641-84b6433afc46, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642069 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 2, commit: true, uuid: 80848dc9-adb6-4bb8-85ff-4398bdf67879, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642069 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 2, commit: true, uuid: fa1df9e5-a150-47c4-a923-752ee14d1aa1, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642075 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 3, commit: true, uuid: df3adb62-c8e0-4919-8c9f-2f15a0cd4ab2, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642075 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 3, commit: true, uuid: 5adb8ad3-0d88-4d69-8bfe-8e9bafad0ed3, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642080 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 4, commit: true, uuid: e4d772ab-2b35-4206-9af8-185d4f4d8d58, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642080 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: nil, error: rejected, commit: false, uuid: a184b6fe-b357-441c-8c64-38839d42edd0, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [warn] 57507#2086044: *642080 [lua] plugin.lua:646: run_plugin(): limit-conn exits with http status code 503, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642080 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 3, error: nil, uuid: 3aeb7266-9c9e-4bbe-9a29-5e164e492339 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642080 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 2, error: nil, uuid: cfe7834a-fdc0-4f83-8641-84b6433afc46 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642080 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 2, error: nil, uuid: 80848dc9-adb6-4bb8-85ff-4398bdf67879 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642080 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 1, error: nil, uuid: fa1df9e5-a150-47c4-a923-752ee14d1aa1 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642080 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 1, error: nil, uuid: df3adb62-c8e0-4919-8c9f-2f15a0cd4ab2 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642080 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 0, error: nil, uuid: 5adb8ad3-0d88-4d69-8bfe-8e9bafad0ed3 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642080 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 0, error: nil, uuid: e4d772ab-2b35-4206-9af8-185d4f4d8d58 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642100 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 1, commit: true, uuid: ea9f0ce7-74df-4f1f-9aeb-6b9a467eca69, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:48 [error] 57507#2086044: *642100 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 1, commit: true, uuid: 725c3868-ebda-47ff-8b41-392c41df516e, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642044 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 0, error: nil, uuid: ea9f0ce7-74df-4f1f-9aeb-6b9a467eca69 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9999/test", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642044 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 0, error: nil, uuid: 725c3868-ebda-47ff-8b41-392c41df516e while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9999/test", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642665 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 1, commit: true, uuid: 0ca768b2-9f32-4154-8608-cb113e3abf73, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642665 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 1, commit: true, uuid: d92e5719-fd09-43b7-89b4-97888b5ed844, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642053 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 0, error: nil, uuid: 0ca768b2-9f32-4154-8608-cb113e3abf73 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9999/test", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642053 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 0, error: nil, uuid: d92e5719-fd09-43b7-89b4-97888b5ed844 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9999/test", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642675 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 1, commit: true, uuid: c1137b68-fb2d-4f50-8946-d14e9fbf11ed, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642675 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 1, commit: true, uuid: 2a6d2c8f-9eaf-4881-ab89-ccfd06439f9d, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642075 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 0, error: nil, uuid: c1137b68-fb2d-4f50-8946-d14e9fbf11ed while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9999/test", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642075 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 0, error: nil, uuid: 2a6d2c8f-9eaf-4881-ab89-ccfd06439f9d while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9999/test", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642687 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 1, commit: true, uuid: 9ee69269-9339-4d49-bcce-f696930f1dc0, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642687 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 1, commit: true, uuid: f14cf90e-62ec-4f17-aead-6bcf4b2492c0, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642700 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 2, commit: true, uuid: 416e5efe-7338-4bdc-a908-3e5afc3ca9b3, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642700 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 2, commit: true, uuid: cd393086-40ad-47b6-9832-3623156ed20a, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642100 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 1, error: nil, uuid: 9ee69269-9339-4d49-bcce-f696930f1dc0 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9999/test", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642100 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 1, error: nil, uuid: f14cf90e-62ec-4f17-aead-6bcf4b2492c0 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9999/test", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642100 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 0, error: nil, uuid: 416e5efe-7338-4bdc-a908-3e5afc3ca9b3 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9999/test", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642100 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 0, error: nil, uuid: cd393086-40ad-47b6-9832-3623156ed20a while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9999/test", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642703 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 1, commit: true, uuid: d03fd518-b76a-4674-84c5-a285a02709cc, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642703 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 1, commit: true, uuid: d1a3a04c-bf6f-462a-97f6-209988b69b79, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642709 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 2, commit: true, uuid: d4f048d7-ff76-4af8-bc14-220f9c5ca86e, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642709 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 2, commit: true, uuid: 098e1ae4-08d1-4a9d-ba4d-92ecaa312dbe, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642712 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: global_rule12707, delay: 0, error: 3, commit: true, uuid: 388eec02-2236-4b7e-be1c-98bfb3bc626d, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:53 [error] 57507#2086044: *642712 [lua] limit-conn.lua:84: phase_func(): before request -> limit key: route12734, delay: 0, error: 3, commit: true, uuid: efde6b50-7d87-455b-ae43-0aa6927220d5, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", host: "localhost:9080"
2021/07/07 17:47:58 [error] 57507#2086044: *642665 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 2, error: nil, uuid: d03fd518-b76a-4674-84c5-a285a02709cc while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9999/test", host: "localhost:9080"
2021/07/07 17:47:58 [error] 57507#2086044: *642665 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 2, error: nil, uuid: d1a3a04c-bf6f-462a-97f6-209988b69b79 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9999/test", host: "localhost:9080"
2021/07/07 17:47:58 [error] 57507#2086044: *642665 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 1, error: nil, uuid: d4f048d7-ff76-4af8-bc14-220f9c5ca86e while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9999/test", host: "localhost:9080"
2021/07/07 17:47:58 [error] 57507#2086044: *642665 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 1, error: nil, uuid: 098e1ae4-08d1-4a9d-ba4d-92ecaa312dbe while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9999/test", host: "localhost:9080"
2021/07/07 17:47:58 [error] 57507#2086044: *642665 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: global_rule12707, conn: 0, error: nil, uuid: 388eec02-2236-4b7e-be1c-98bfb3bc626d while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9999/test", host: "localhost:9080"
2021/07/07 17:47:58 [error] 57507#2086044: *642665 [lua] limit-conn.lua:130: phase_func(): after request -> limit key: route12734, conn: 0, error: nil, uuid: efde6b50-7d87-455b-ae43-0aa6927220d5 while logging request, client: 127.0.0.1, server: _, request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9999/test", host: "localhost:9080"

first :

From the above log, we can clearly see that the request with uuid 95ef8140-59e5-4adb-aef3-55d0fa291568 reached the limit of the routing plug-in, so it was intercepted and returned 503, but why his return would cause uuid to be d147e58c-759e- How about the request of 405f-ad75-3d216d54ef20 entering the log phase in advance?

second:

I am obviously a concurrent request. Why is the time of the first log differing from the time of the last log by nearly 10 seconds?

What's the expected result?

I configured the route to limit 3 concurrency, and the global rule limits 5 concurrency. The expected result should be 20 requests, only 3 can pass, and the rest should be restricted.

@tokers
Copy link
Contributor

tokers commented Jul 7, 2021

That's a known issue, we should avoid running same plugins both in global rules and routes (especially with same configurations).

@zuiyangqingzhou
Copy link
Contributor Author

Are there any plans to fix this problem? Because some scenarios require global rules to cooperate with routes

@tzssangglass
Copy link
Member

we can consider optimizing the limit key of the limit-req plugin so that the key can be distinguished.

@zuiyangqingzhou
Copy link
Contributor Author

we can consider optimizing the limit key of the limit-req plugin so that the key can be distinguished.

I'm not sure if we are discussing the same issue, because I am emphasizing the limit-conn plugin, or is this the same type of issue?

What is the root cause of this problem? Because I see the source code has a conf_type field to distinguish the global plugin and the plugin on the router.

@tzssangglass
Copy link
Member

I'm not sure if we are discussing the same issue, because I am emphasizing the limit-conn plugin, or is this the same type of issue?

My mistake, I meant to say that the three similar plugins of limit-*

@membphis
Copy link
Member

@zuiyangqingzhou you can make a try with this patch.

diff --git a/apisix/plugins/limit-conn.lua b/apisix/plugins/limit-conn.lua
index 564a1b54c..dc8d22c44 100644
--- a/apisix/plugins/limit-conn.lua
+++ b/apisix/plugins/limit-conn.lua
@@ -129,6 +129,7 @@ function _M.log(conf, ctx)
     end

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

@zuiyangqingzhou
Copy link
Contributor Author

@zuiyangqingzhou you can make a try with this patch.

diff --git a/apisix/plugins/limit-conn.lua b/apisix/plugins/limit-conn.lua
index 564a1b54c..dc8d22c44 100644
--- a/apisix/plugins/limit-conn.lua
+++ b/apisix/plugins/limit-conn.lua
@@ -129,6 +129,7 @@ function _M.log(conf, ctx)
     end

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

great, verified to solve the current problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants