From dff68605568fff8f4005a9342788ffa4905632cc Mon Sep 17 00:00:00 2001 From: Kong Team Gateway Bot <98048765+team-gateway-bot@users.noreply.github.com> Date: Wed, 20 Sep 2023 06:11:34 -0500 Subject: [PATCH] fix(queues): shutdown flag needs to be checked while waiting (#11456) (#11608) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous fix (#11376) to enable batching during shutdown failed to check the shutdown flag while waiting for more items to batch. If the coalescing delay was large enough, this could cause the last batch to be lost. (cherry picked from commit 3bf77d7455d019455c017e8e43d05e444bf78c86) Co-authored-by: Hans Hübner --- kong/tools/queue.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kong/tools/queue.lua b/kong/tools/queue.lua index c1221ef67b02..5e9386c65434 100644 --- a/kong/tools/queue.lua +++ b/kong/tools/queue.lua @@ -242,6 +242,12 @@ function Queue:process_once() -- so that we can check for worker shutdown periodically. local wait_time = math_min(self.max_coalescing_delay - (now() - data_started), COALESCE_POLL_TIME) + if ngx.worker.exiting() then + -- minimize coalescing delay during shutdown to quickly process remaining entries + self.max_coalescing_delay = COALESCE_MIN_TIME + wait_time = COALESCE_MIN_TIME + end + ok, err = self.semaphore:wait(wait_time) if not ok and err ~= "timeout" then self:log_err("could not wait for semaphore: %s", err)