Skip to content

Commit

Permalink
fix(queues): shutdown flag needs to be checked while waiting (#11456)
Browse files Browse the repository at this point in the history
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 3bf77d7)
  • Loading branch information
hanshuebner committed Sep 20, 2023
1 parent 0217082 commit 8484127
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions kong/tools/queue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8484127

Please sign in to comment.