#2236·rq

Workers Get Killed When Dequeuing A Job

Author: adiarbiliCreated Apr 20, 2025Updated Sep 28, 2026

I encounter a case where a worker gets SIGTERM signal and the job was about to execute become an orphaned. After investigating worker.py code I found out these lines which are not under a critical section:https://github.com/rq/rq/blob/71bc13efc2c1db12e6a0ecd959a7aae47580e741/rq/worker.py#L616-L625

It appears that if the job is dequeued at line 616 and gets SIGTERM signal before line 625 is executed, we result in an orphaned job. It happens due to the fact that the state of the worker is updated to "WorkerStatus.BUSY" only at the execution of line 625.

Reproduction Code:

timeout = None if burst else self.dequeue_timeout
result = self.dequeue_job_and_maintain_ttl(timeout, max_idle_time)
if result is None:
    if burst:
        self.log.info('Worker %s: done, quitting', self.key)
    elif max_idle_time is not None:
        self.log.info('Worker %s: idle for %d seconds, quitting', self.key, max_idle_time)
    break


job, queue = result
self.log.info("Going to sleep for 20s")
time.sleep(20)
# Send SIGTERM when sleeping occurs
self.execute_job(job, queue)