From e92682c83aefda9475eba3dd9fe0ef42575d92b7 Mon Sep 17 00:00:00 2001 From: Marcus Ong Date: Fri, 3 Mar 2023 07:02:07 +0800 Subject: [PATCH] Fix TimerDeathPenalty not properly handling negative/infinite timeout (#1845) * Fix TimerDeathPenalty not properly handling negative/infinite timeout * revert back to using exc_info --------- Co-authored-by: Marcus --- rq/timeouts.py | 4 ++++ tests/test_timeouts.py | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/rq/timeouts.py b/rq/timeouts.py index a1401c5c..44f01f9e 100644 --- a/rq/timeouts.py +++ b/rq/timeouts.py @@ -110,10 +110,14 @@ class TimerDeathPenalty(BaseDeathPenalty): def setup_death_penalty(self): """Starts the timer.""" + if self._timeout <= 0: + return self._timer = self.new_timer() self._timer.start() def cancel_death_penalty(self): """Cancels the timer.""" + if self._timeout <= 0: + return self._timer.cancel() self._timer = None diff --git a/tests/test_timeouts.py b/tests/test_timeouts.py index 2872ee02..1f392a38 100644 --- a/tests/test_timeouts.py +++ b/tests/test_timeouts.py @@ -42,3 +42,10 @@ class TestTimeouts(RQTestCase): self.assertIn(job, failed_job_registry) job.refresh() self.assertIn("rq.timeouts.JobTimeoutException", job.exc_info) + + # Test negative timeout doesn't raise JobTimeoutException, + # which implies an unintended immediate timeout. + job = q.enqueue(thread_friendly_sleep_func, args=(1,), job_timeout=-1) + w.work(burst=True) + job.refresh() + self.assertIn(job, finished_job_registry)