Skip to content

[19.0][FIX] queue_job: wake the job runner up on stop - #1011

Open
HoloborodkoBohdan wants to merge 1 commit into
OCA:19.0from
HoloborodkoBohdan:19.0-fix-queue_job-runner_stop_wakeup
Open

HoloborodkoBohdan wants to merge 1 commit into
OCA:19.0from
HoloborodkoBohdan:19.0-fix-queue_job-runner_stop_wakeup

Conversation

@HoloborodkoBohdan

Copy link
Copy Markdown
Contributor

A runner that lost the master election (or hit an error) waits ERROR_RECOVERY_DELAY with time.sleep, and the runner thread and worker wait START_DELAY the same way before starting. stop() cannot interrupt either, and since the server joins the runner thread on shutdown, the whole process waits up to 5 seconds before it exits.

With several workers each starting a runner, only one wins the election and the others spend most of their time in that sleep. On hosts that send SIGKILL a few seconds after asking a process to stop (odoo.sh allows about 5 s), those processes get killed instead of exiting: on one production day, 141 of 538 worker shutdowns ended in SIGKILL, all of them during this sleep.

Both delays now wait on a threading.Event that stop() sets.

Measured locally (Odoo 19, threaded server, master lock held by another session, SIGTERM at different points of the 5 s cycle): from "graceful stop requested" to "stopped" took 0.7-4.4 s before, about 1 ms after.

Two tests added; both fail on the current 19.0 branch

A runner that lost the master election, or hit an error, slept
ERROR_RECOVERY_DELAY with time.sleep, and the start delay slept
START_DELAY the same way. stop() could not interrupt either, and the
server joins the runner thread on shutdown, so the whole process waited
up to 5 seconds. On hosts that kill a process a few seconds after asking
it to stop, a process whose runner was not the master was killed instead
of exiting.

Both delays now wait on an event that stop() sets.
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @sbidoul, @guewen,
some modules you are maintaining are being modified, check this out!

@amh-mw amh-mw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review only, LGTM.

Would you kindly prefix the issue title with [19.0]? It will make it easier to keep things organized when this fix is ported to other branches.

@HoloborodkoBohdan HoloborodkoBohdan changed the title [FIX] queue_job: wake the job runner up on stop [19.0][FIX] queue_job: wake the job runner up on stop Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants