From 398e5d336de266bddbb072644146efe4d6aa0b57 Mon Sep 17 00:00:00 2001 From: Michael Martin <3277009+flrgh@users.noreply.github.com> Date: Thu, 15 Sep 2022 21:15:27 -0700 Subject: [PATCH 1/3] fix(cli): shut down timers at the end of execution --- CHANGELOG.md | 5 +++++ kong/cmd/init.lua | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ab3928e44b0..ad89c9c3f1b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -94,6 +94,11 @@ the router's mutex is not released properly. [#9480](https://github.com/Kong/kong/pull/9480) +#### CLI + +- Fix poor CLI performance due to pending timer jobs + [#9536](https://github.com/Kong/kong/pull/9536) + #### Admin API - Increase the maximum request argument number from `100` to `1000`, and return 400 error if request parameters reach the limitation to avoid being truncated. diff --git a/kong/cmd/init.lua b/kong/cmd/init.lua index a25ffba43e36..1f8feda39b3f 100644 --- a/kong/cmd/init.lua +++ b/kong/cmd/init.lua @@ -5,6 +5,15 @@ math.randomseed() -- Generate PRNG seed local pl_app = require "pl.lapp" local log = require "kong.cmd.utils.log" +local timerng = _G.timerng + +local function stop_timers() + -- shutdown lua-resty-timer-ng to allow the nginx worker to stop quickly + if timerng then + timerng:destroy() + end +end + local options = [[ --v verbose --vv debug @@ -99,4 +108,6 @@ return function(args) pl_app.quit(nil, true) end) + + stop_timers() end From f5d4b7d92848a6f2140618fc9f75b937de8c229c Mon Sep 17 00:00:00 2001 From: Michael Martin <3277009+flrgh@users.noreply.github.com> Date: Wed, 12 Oct 2022 11:44:16 -0700 Subject: [PATCH 2/3] fix(cli): do not cache global timer instance --- kong/cmd/init.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kong/cmd/init.lua b/kong/cmd/init.lua index 1f8feda39b3f..be38c6ac5619 100644 --- a/kong/cmd/init.lua +++ b/kong/cmd/init.lua @@ -5,12 +5,10 @@ math.randomseed() -- Generate PRNG seed local pl_app = require "pl.lapp" local log = require "kong.cmd.utils.log" -local timerng = _G.timerng - local function stop_timers() -- shutdown lua-resty-timer-ng to allow the nginx worker to stop quickly - if timerng then - timerng:destroy() + if _G.timerng then + _G.timerng:destroy() end end From 1f40e4c497b1d2504e1ff2abfda0a8edcbe737d3 Mon Sep 17 00:00:00 2001 From: Datong Sun Date: Mon, 17 Oct 2022 11:10:15 +0800 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad89c9c3f1b4..1ae72792b33d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -96,7 +96,7 @@ #### CLI -- Fix poor CLI performance due to pending timer jobs +- Fix slow CLI performance due to pending timer jobs [#9536](https://github.com/Kong/kong/pull/9536) #### Admin API