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

fix(queues): shutdown flag needs to be checked while waiting #11456

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions kong/tools/queue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,19 @@ function Queue:process_once()

-- We've got our first entry from the queue. Collect more entries until max_coalescing_delay expires or we've collected
-- max_batch_size entries to send
if ngx.worker.exiting() then
-- minimize coalescing delay during shutdown to quickly process remaining entries
self.max_coalescing_delay = COALESCE_MIN_TIME
end
while entry_count < self.max_batch_size
and self.max_coalescing_delay - (now() - data_started) >= COALESCE_MIN_TIME
do
-- Instead of waiting for the coalesce time to expire, we cap the semaphore wait to COALESCE_POLL_TIME
-- 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
Loading