From 351de4d9a3655e3b3309f6d92168f7f38fcf3460 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 10 Jul 2025 14:13:08 +0200 Subject: [PATCH] Fix GROUP_THROTTLE_WAIT concurrency setting We need to use the QUEUE concurrency setting instead of GROUP_QUEUE for the GROUP_THROTTLE_WAIT execution limit. Otherwise the test_jobs_decorator.py::test_execution_limit_group_throttle_wait test deadlocks. The reason this deadlocks is because GROUP_QUEUE concurrency doesn't really work because we only can release a group lock if the job is actually running. Or put differently, throttling isn't supported with GROUP_* concurrency options. --- supervisor/jobs/decorator.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/supervisor/jobs/decorator.py b/supervisor/jobs/decorator.py index 11c4384fc..bef6b89f5 100644 --- a/supervisor/jobs/decorator.py +++ b/supervisor/jobs/decorator.py @@ -111,7 +111,7 @@ class Job(CoreSysAttributes): JobExecutionLimit.GROUP_WAIT: (JobConcurrency.GROUP_QUEUE, None), JobExecutionLimit.GROUP_THROTTLE: (None, JobThrottle.GROUP_THROTTLE), JobExecutionLimit.GROUP_THROTTLE_WAIT: ( - JobConcurrency.GROUP_QUEUE, + JobConcurrency.QUEUE, # Seems a bit counter intuitive, but GROUP_QUEUE deadlocks tests/jobs/test_job_decorator.py::test_execution_limit_group_throttle_wait JobThrottle.GROUP_THROTTLE, ), JobExecutionLimit.GROUP_THROTTLE_RATE_LIMIT: ( @@ -148,6 +148,19 @@ class Job(CoreSysAttributes): ) self._rate_limited_calls = {} + if self.throttle in ( + JobThrottle.GROUP_THROTTLE, + JobThrottle.GROUP_RATE_LIMIT, + ) and self.concurrency in ( + JobConcurrency.GROUP_REJECT, + JobConcurrency.GROUP_QUEUE, + ): + # We cannot release group locks when Job is not running (e.g. throttled) + # which makes these combinations impossible to use currently. + raise RuntimeError( + f"Job {self.name} is using group throttling ({self.throttle}) with group concurrency ({self.concurrency}), which is not allowed!" + ) + @property def throttle_max_calls(self) -> int: """Return max calls for throttle."""