From c826a558aa5af5f50a87094876e5df599e42a37c Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Fri, 23 Feb 2024 16:06:39 +0800 Subject: [PATCH 01/13] feat: support get last peer connection cached Signed-off-by: tzssangglass --- lualib/resty/kong/peer_conn.lua | 47 +++++++++++ src/ngx_http_lua_kong_peer_connection.c | 30 +++++++ t/011-get_last_peer_connection_cached.t | 106 ++++++++++++++++++++++++ 3 files changed, 183 insertions(+) create mode 100644 lualib/resty/kong/peer_conn.lua create mode 100644 src/ngx_http_lua_kong_peer_connection.c create mode 100644 t/011-get_last_peer_connection_cached.t diff --git a/lualib/resty/kong/peer_conn.lua b/lualib/resty/kong/peer_conn.lua new file mode 100644 index 00000000..98f3c036 --- /dev/null +++ b/lualib/resty/kong/peer_conn.lua @@ -0,0 +1,47 @@ +local ffi = require "ffi" +local C = ffi.C +local base = require "resty.core.base" +local ffi_str = ffi.string +local orig_get_request = base.get_request +local get_phase = ngx.get_phase +local error = error +local NGX_ERROR = ngx.ERROR + +ffi.cdef[[ +int +ngx_http_lua_kong_ffi_get_last_peer_connection_cached(ngx_http_request_t *r, + char **err); +]] + +local errmsg = base.get_errmsg_ptr() + +local function get_request() + local r = orig_get_request() + + if not r then + error("no request found") + end + + return r +end + + +local function get_last_peer_connection_cached() + if get_phase() ~= "balancer" then + error("get_last_peer_connection_cached can only be called in balancer phase") + end + + local r = get_request() + + local rc = C.ngx_http_lua_kong_ffi_get_last_peer_connection_cached(r, errmsg) + + if rc == NGX_ERROR then + error(ffi_str(errmsg[0]), 2) + end + + return rc +end + +return { + get_last_peer_connection_cached = get_last_peer_connection_cached, +} \ No newline at end of file diff --git a/src/ngx_http_lua_kong_peer_connection.c b/src/ngx_http_lua_kong_peer_connection.c new file mode 100644 index 00000000..15bc31a7 --- /dev/null +++ b/src/ngx_http_lua_kong_peer_connection.c @@ -0,0 +1,30 @@ +/** + * Copyright 2019-2024 Kong Inc. + + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://www.apache.org/licenses/LICENSE-2.0 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "ngx_http_lua_common.h" + +int +ngx_http_lua_kong_ffi_get_last_peer_connection_cached(ngx_http_request_t *r, + char **err) +{ + if (r->upstream == NULL) { + *err = "no upstream found"; + return NGX_ERROR; + } + + return r->upstream->peer.cached; +} diff --git a/t/011-get_last_peer_connection_cached.t b/t/011-get_last_peer_connection_cached.t new file mode 100644 index 00000000..9da401df --- /dev/null +++ b/t/011-get_last_peer_connection_cached.t @@ -0,0 +1,106 @@ +# vim:set ft= ts=4 sw=4 et: + +use Test::Nginx::Socket::Lua; +use Cwd qw(cwd); + +log_level('info'); +repeat_each(1); + +plan tests => repeat_each() * (blocks() * 2); + +my $pwd = cwd(); + +no_long_string(); +run_tests(); + + +__DATA__ + +=== TEST 1: sanity +--- http_config + lua_package_path "../lua-resty-core/lib/?.lua;lualib/?.lua;;"; +--- http_config + lua_shared_dict request_counter 1m; + upstream my_upstream { + server 127.0.0.1; + balancer_by_lua_block { + local peer_conn = require("resty.kong.peer_conn") + local last_peer_connection_cached = peer_conn.get_last_peer_connection_cached() + ngx.log(ngx.INFO, "last_peer_connection_cached ", tostring(last_peer_connection_cached)) + + local balancer = require "ngx.balancer" + local host = "127.0.0.1" + local port = 8090; + + local pool = host .. "|" .. port + local pool_opts = { + pool = pool, + pool_size = 512, + } + + local ok, err = balancer.set_current_peer(host, port, pool_opts) + if not ok then + ngx.log(ngx.ERR, "failed to set the current peer: ", err) + return ngx.exit(500) + end + + balancer.set_timeouts(60000, 60000, 60000) + + local ok, err = balancer.enable_keepalive(60, 100) + if not ok then + ngx.log(ngx.ERR, "failed to enable keepalive: ", err) + return ngx.exit(500) + end + } + } + + server { + listen 0.0.0.0:8090; + location /hello { + content_by_lua_block{ + local request_counter = ngx.shared.request_counter + local first_request = request_counter:get("first_request") + if first_request == nil then + request_counter:set("first_request", "yes") + ngx.say("hello") + else + ngx.exit(ngx.HTTP_CLOSE) + end + } + } + } +--- config + location /hello { + proxy_pass http://my_upstream; + proxy_set_header Connection "keep-alive"; + } + + location = /t { + content_by_lua_block { + local http = require "resty.http" + local httpc = http.new() + local uri = "http://127.0.0.1:" .. ngx.var.server_port + .. "/hello" + local res, err = httpc:request_uri(uri) + if not res then + ngx.say(err) + return + end + + res, err = httpc:request_uri(uri) + if not res then + ngx.say(err) + return + end + } + } +--- request +GET /t +--- error_code eval +[200, 502] +--- grep_error_log eval +qr/last_peer_connection_cached \d+/ +--- grep_error_log_out +last_peer_connection_cached 0 +last_peer_connection_cached 0 +last_peer_connection_cached 1 From b8cc5a5e8b3f46f35820e679c1e8cd5a1b7ffea8 Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Fri, 23 Feb 2024 17:34:26 +0800 Subject: [PATCH 02/13] add file to compile Signed-off-by: tzssangglass --- config | 1 + 1 file changed, 1 insertion(+) diff --git a/config b/config index 6c64b0e5..b9b84c57 100644 --- a/config +++ b/config @@ -10,6 +10,7 @@ ngx_module_srcs=" \ $ngx_addon_dir/src/ngx_http_lua_kong_log_handler.c \ $ngx_addon_dir/src/ngx_http_lua_kong_vars.c \ $ngx_addon_dir/src/ssl/ngx_lua_kong_ssl.c \ + $ngx_addon_dir/src/ngx_http_lua_kong_peer_connection.c \ " ngx_module_incs="$ngx_addon_dir/src" From ea7a29dc09401fe2d20244b2ccd2c1afebb3e0b9 Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Fri, 23 Feb 2024 18:25:26 +0800 Subject: [PATCH 03/13] disable build cache Signed-off-by: tzssangglass --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 10d24289..f262e86d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -52,13 +52,13 @@ jobs: key: ${{ hashFiles('src/**', 'lualib/**', '.github/workflows/tests.yml', 'kong/.requirements') }} - name: Install packages - if: steps.cache-deps.outputs.cache-hit != 'true' + # if: steps.cache-deps.outputs.cache-hit != 'true' run: | sudo apt update sudo apt install libyaml-dev valgrind libprotobuf-dev cpanminus net-tools libpcre3-dev build-essential - name: Build Kong - if: steps.cache-deps.outputs.cache-hit != 'true' + # if: steps.cache-deps.outputs.cache-hit != 'true' env: GH_TOKEN: ${{ github.token }} run: | From 411e329017c3bc84e432387c93979a9d3a8f4d94 Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Mon, 26 Feb 2024 15:53:29 +0800 Subject: [PATCH 04/13] apply comments Signed-off-by: tzssangglass --- lualib/resty/kong/peer_conn.lua | 2 +- src/ngx_http_lua_kong_peer_connection.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lualib/resty/kong/peer_conn.lua b/lualib/resty/kong/peer_conn.lua index 98f3c036..c6a32d2d 100644 --- a/lualib/resty/kong/peer_conn.lua +++ b/lualib/resty/kong/peer_conn.lua @@ -28,7 +28,7 @@ end local function get_last_peer_connection_cached() if get_phase() ~= "balancer" then - error("get_last_peer_connection_cached can only be called in balancer phase") + error("get_last_peer_connection_cached() can only be called in balancer phase") end local r = get_request() diff --git a/src/ngx_http_lua_kong_peer_connection.c b/src/ngx_http_lua_kong_peer_connection.c index 15bc31a7..e992530f 100644 --- a/src/ngx_http_lua_kong_peer_connection.c +++ b/src/ngx_http_lua_kong_peer_connection.c @@ -15,7 +15,7 @@ */ -#include "ngx_http_lua_common.h" +#include "ngx_http_lua_kong_common.h" int ngx_http_lua_kong_ffi_get_last_peer_connection_cached(ngx_http_request_t *r, From 9670f5ede32d3ed9bb2bdc503c69187b4b0b81a6 Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Wed, 28 Feb 2024 15:55:12 +0800 Subject: [PATCH 05/13] apply comments Signed-off-by: tzssangglass --- config | 2 +- lualib/resty/kong/peer_conn.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config b/config index b9b84c57..0404fed9 100644 --- a/config +++ b/config @@ -9,8 +9,8 @@ ngx_module_srcs=" \ $ngx_addon_dir/src/ngx_http_lua_kong_log.c \ $ngx_addon_dir/src/ngx_http_lua_kong_log_handler.c \ $ngx_addon_dir/src/ngx_http_lua_kong_vars.c \ + $ngx_addon_dir/src/ngx_http_lua_kong_peer_connection.c \ $ngx_addon_dir/src/ssl/ngx_lua_kong_ssl.c \ - $ngx_addon_dir/src/ngx_http_lua_kong_peer_connection.c \ " ngx_module_incs="$ngx_addon_dir/src" diff --git a/lualib/resty/kong/peer_conn.lua b/lualib/resty/kong/peer_conn.lua index c6a32d2d..64494718 100644 --- a/lualib/resty/kong/peer_conn.lua +++ b/lualib/resty/kong/peer_conn.lua @@ -44,4 +44,4 @@ end return { get_last_peer_connection_cached = get_last_peer_connection_cached, -} \ No newline at end of file +} From 9819990307dfee86b560b45e76912dd34f9c4421 Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Thu, 29 Feb 2024 11:24:25 +0800 Subject: [PATCH 06/13] apply comments Signed-off-by: tzssangglass --- config | 2 +- lualib/resty/kong/peer_conn.lua | 11 +++++++---- src/ngx_http_lua_kong_peer_connection.c | 3 +++ t/011-get_last_peer_connection_cached.t | 3 +-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/config b/config index 0404fed9..043ec536 100644 --- a/config +++ b/config @@ -9,7 +9,7 @@ ngx_module_srcs=" \ $ngx_addon_dir/src/ngx_http_lua_kong_log.c \ $ngx_addon_dir/src/ngx_http_lua_kong_log_handler.c \ $ngx_addon_dir/src/ngx_http_lua_kong_vars.c \ - $ngx_addon_dir/src/ngx_http_lua_kong_peer_connection.c \ + $ngx_addon_dir/src/ngx_http_lua_kong_peer_connection.c \ $ngx_addon_dir/src/ssl/ngx_lua_kong_ssl.c \ " diff --git a/lualib/resty/kong/peer_conn.lua b/lualib/resty/kong/peer_conn.lua index 64494718..d27d18aa 100644 --- a/lualib/resty/kong/peer_conn.lua +++ b/lualib/resty/kong/peer_conn.lua @@ -1,19 +1,22 @@ local ffi = require "ffi" -local C = ffi.C local base = require "resty.core.base" -local ffi_str = ffi.string + local orig_get_request = base.get_request +local errmsg = base.get_errmsg_ptr() +local C = ffi.C +local ffi_str = ffi.string local get_phase = ngx.get_phase -local error = error local NGX_ERROR = ngx.ERROR +local error = error + + ffi.cdef[[ int ngx_http_lua_kong_ffi_get_last_peer_connection_cached(ngx_http_request_t *r, char **err); ]] -local errmsg = base.get_errmsg_ptr() local function get_request() local r = orig_get_request() diff --git a/src/ngx_http_lua_kong_peer_connection.c b/src/ngx_http_lua_kong_peer_connection.c index e992530f..e431073f 100644 --- a/src/ngx_http_lua_kong_peer_connection.c +++ b/src/ngx_http_lua_kong_peer_connection.c @@ -17,6 +17,7 @@ #include "ngx_http_lua_kong_common.h" + int ngx_http_lua_kong_ffi_get_last_peer_connection_cached(ngx_http_request_t *r, char **err) @@ -26,5 +27,7 @@ ngx_http_lua_kong_ffi_get_last_peer_connection_cached(ngx_http_request_t *r, return NGX_ERROR; } + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "last_peer_connection_cached %d", r->upstream->peer.cached); return r->upstream->peer.cached; } diff --git a/t/011-get_last_peer_connection_cached.t b/t/011-get_last_peer_connection_cached.t index 9da401df..9ee143d8 100644 --- a/t/011-get_last_peer_connection_cached.t +++ b/t/011-get_last_peer_connection_cached.t @@ -3,7 +3,7 @@ use Test::Nginx::Socket::Lua; use Cwd qw(cwd); -log_level('info'); +log_level('debug'); repeat_each(1); plan tests => repeat_each() * (blocks() * 2); @@ -26,7 +26,6 @@ __DATA__ balancer_by_lua_block { local peer_conn = require("resty.kong.peer_conn") local last_peer_connection_cached = peer_conn.get_last_peer_connection_cached() - ngx.log(ngx.INFO, "last_peer_connection_cached ", tostring(last_peer_connection_cached)) local balancer = require "ngx.balancer" local host = "127.0.0.1" From cd967cf2b422f0981f16483cc802237584ea966d Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Tue, 5 Mar 2024 16:36:43 +0800 Subject: [PATCH 07/13] add desc in README.md Signed-off-by: tzssangglass --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index a6cf30f8..1f0645c3 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ Table of Contents * [resty.kong.tag.get](#restykongtagget) * [resty.kong.log.set\_log\_level](#restykonglogset_log_level) * [resty.kong.log.get\_log\_level](#restykonglogget_log_level) + * [resty.kong.peer_conn.get\_last\_peer\_connection\_cached](#restykongpeer_connget_last_peer_connection_cached) * [License](#license) Description @@ -476,6 +477,22 @@ for the possible value of `level`. [Back to TOC](#table-of-contents) +resty.kong.peer_conn.get\_last\_peer\_connection\_cached +---------------------------------- +**syntax:** *resty.kong.peer_conn.get_last_peer_connection_cached()* + +**context:** *balancer_by_lua* + +**subsystems:** *http* + +Retrieves whether the connection used in the previous attempt came from the upstream connection pool when the next_upstream retrying mechanism is in action. + +Possible result are as follows: + +- `0`: The connection was not reused from the upstream connection pool, it means that a new connection was created with the upstream in the previous attempt. +- `1`: The connection was reused from the upstream connection pool, it means that no new connection was created with the upstream in the previous attempt. + +[Back to TOC](#table-of-contents) License ======= From 2e36301d0e49ea0849c23c658d9092d4742014c2 Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Wed, 13 Mar 2024 13:02:00 +0800 Subject: [PATCH 08/13] fix comments Signed-off-by: tzssangglass --- README.md | 44 ++++++++++++++++++++++++++++++--- lualib/resty/kong/peer_conn.lua | 2 +- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1f0645c3..cb3b64cf 100644 --- a/README.md +++ b/README.md @@ -485,12 +485,48 @@ resty.kong.peer_conn.get\_last\_peer\_connection\_cached **subsystems:** *http* -Retrieves whether the connection used in the previous attempt came from the upstream connection pool when the next_upstream retrying mechanism is in action. +This function retrieves information about whether the connection used in the previous attempt came from the upstream connection pool when the next_upstream retrying mechanism is in action. -Possible result are as follows: +The possible results are as follows: +- `false`: Indicates the connection was not reused from the upstream connection pool, meaning a new connection was created with the upstream in the previous attempt. +- `true`: Indicates the connection was reused from the upstream connection pool, meaning no new connection was created with the upstream in the previous attempt. -- `0`: The connection was not reused from the upstream connection pool, it means that a new connection was created with the upstream in the previous attempt. -- `1`: The connection was reused from the upstream connection pool, it means that no new connection was created with the upstream in the previous attempt. +After applying the [dynamic upstream keepalive patch](https://github.com/Kong/kong/blob/3.6.0/build/openresty/patches/ngx_lua-0.10.26_01-dyn_upstream_keepalive.patch), +Nginx's upstream module attempts to retrieve connections from the upstream connection pool for each retry. +If the obtained connection is deemed unusable, Nginx considers that retry invalid and performs a compensatory retry. + +Since each retry triggers the `balancer_by_lua` phase, the number of retries logged in Lua land during this phase may exceed the maximum limit set by `set_more_tries`. + +Using this function in the `balancer_by_lua` phase allows for determining if the connection used in the previous retry was taken from the connection pool. +If the return value is `true`, it indicates that the connection from the pool used in the previous retry was unusable, rendering that retry void. + +The value returned by this function helps in accurately assessing the actual number of new connections established with the upstream server during the retry process during the `balancer_by_lua phase`. + +Example: +```lua +local peer_conn = require("resty.kong.peer_conn") + +balancer_by_lua_block { + local ctx = ngx.ctx + + ctx.tries = ctx.tries or {} + local tries = ctx.tries + + -- update the number of tries + local try_count = #tries + 1 + + -- fetch the last peer connection cached + local last_peer_connection_cached = peer_conn.get_last_peer_connection_cached() + if try_count > 1 then + local previous_try = tries[try_count - 1] + last_peer_connection_cached = previous_try.connection_reused + else + last_peer_connection_cached = false + end + + ... +} +``` [Back to TOC](#table-of-contents) diff --git a/lualib/resty/kong/peer_conn.lua b/lualib/resty/kong/peer_conn.lua index d27d18aa..43e5b61c 100644 --- a/lualib/resty/kong/peer_conn.lua +++ b/lualib/resty/kong/peer_conn.lua @@ -42,7 +42,7 @@ local function get_last_peer_connection_cached() error(ffi_str(errmsg[0]), 2) end - return rc + return rc == 1 end return { From 074da4f4b2ef72b0ba3555ded543fb20b5507018 Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Thu, 14 Mar 2024 11:09:31 +0800 Subject: [PATCH 09/13] update Signed-off-by: tzssangglass --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cb3b64cf..f6b2ba35 100644 --- a/README.md +++ b/README.md @@ -504,8 +504,6 @@ The value returned by this function helps in accurately assessing the actual num Example: ```lua -local peer_conn = require("resty.kong.peer_conn") - balancer_by_lua_block { local ctx = ngx.ctx @@ -516,12 +514,13 @@ balancer_by_lua_block { local try_count = #tries + 1 -- fetch the last peer connection cached + local peer_conn = require("resty.kong.peer_conn") local last_peer_connection_cached = peer_conn.get_last_peer_connection_cached() if try_count > 1 then local previous_try = tries[try_count - 1] - last_peer_connection_cached = previous_try.connection_reused + previous_try.cached = peer_conn.get_last_peer_connection_cached() else - last_peer_connection_cached = false + tries[try_count].cached = false end ... From 6a0492da2c28b4cde50a8965e48dfa1b312beda1 Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Thu, 14 Mar 2024 14:15:18 +0800 Subject: [PATCH 10/13] apply comments Signed-off-by: tzssangglass --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f6b2ba35..480a76e6 100644 --- a/README.md +++ b/README.md @@ -479,7 +479,7 @@ for the possible value of `level`. resty.kong.peer_conn.get\_last\_peer\_connection\_cached ---------------------------------- -**syntax:** *resty.kong.peer_conn.get_last_peer_connection_cached()* +**syntax:** *res = resty.kong.peer_conn.get_last_peer_connection_cached()* **context:** *balancer_by_lua* From 0cd95cc1bdd2f1d025aa4738db93abc17f20f212 Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Fri, 15 Mar 2024 15:49:18 +0800 Subject: [PATCH 11/13] restore cache in ga Signed-off-by: tzssangglass --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f262e86d..10d24289 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -52,13 +52,13 @@ jobs: key: ${{ hashFiles('src/**', 'lualib/**', '.github/workflows/tests.yml', 'kong/.requirements') }} - name: Install packages - # if: steps.cache-deps.outputs.cache-hit != 'true' + if: steps.cache-deps.outputs.cache-hit != 'true' run: | sudo apt update sudo apt install libyaml-dev valgrind libprotobuf-dev cpanminus net-tools libpcre3-dev build-essential - name: Build Kong - # if: steps.cache-deps.outputs.cache-hit != 'true' + if: steps.cache-deps.outputs.cache-hit != 'true' env: GH_TOKEN: ${{ github.token }} run: | From 05d3985b5922714b945d381ef88440ef659c353a Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Sat, 16 Mar 2024 16:28:56 +0800 Subject: [PATCH 12/13] fix Signed-off-by: tzssangglass --- lualib/resty/kong/peer_conn.lua | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/lualib/resty/kong/peer_conn.lua b/lualib/resty/kong/peer_conn.lua index 43e5b61c..4f34d18b 100644 --- a/lualib/resty/kong/peer_conn.lua +++ b/lualib/resty/kong/peer_conn.lua @@ -1,7 +1,7 @@ local ffi = require "ffi" local base = require "resty.core.base" -local orig_get_request = base.get_request +local get_request = base.get_request local errmsg = base.get_errmsg_ptr() local C = ffi.C local ffi_str = ffi.string @@ -18,17 +18,6 @@ ngx_http_lua_kong_ffi_get_last_peer_connection_cached(ngx_http_request_t *r, ]] -local function get_request() - local r = orig_get_request() - - if not r then - error("no request found") - end - - return r -end - - local function get_last_peer_connection_cached() if get_phase() ~= "balancer" then error("get_last_peer_connection_cached() can only be called in balancer phase") From 82d0e200fa1a226e1233ea9e25ee3d1c62c135cb Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Mon, 18 Mar 2024 10:57:34 +0800 Subject: [PATCH 13/13] apply conmments Signed-off-by: tzssangglass --- lualib/resty/kong/peer_conn.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lualib/resty/kong/peer_conn.lua b/lualib/resty/kong/peer_conn.lua index 4f34d18b..0ff6feb8 100644 --- a/lualib/resty/kong/peer_conn.lua +++ b/lualib/resty/kong/peer_conn.lua @@ -24,6 +24,9 @@ local function get_last_peer_connection_cached() end local r = get_request() + if not r then + error("no request found") + end local rc = C.ngx_http_lua_kong_ffi_get_last_peer_connection_cached(r, errmsg)