Skip to content

Commit 3deff3d

Browse files
committed
Release blocked executions whose job class no longer resolves
BlockedExecution#release called Semaphore.wait(job) unconditionally, and the semaphore proxy dereferences job.concurrency_limit and job.concurrency_duration, which are delegated to job_class — nil when the job's class was renamed or removed between deploys. The release transaction raised DelegationError and rolled back, so the dispatcher's concurrency maintenance picked up the same blocked execution and crashed again on every tick, forever, and the row was never cleaned up. Job#concurrency_limited? already treats jobs without a resolvable class as not limited, and Job#acquire_concurrency_lock consults it before touching the semaphore; the blocked execution release path was the only one that didn't. Apply the same guard there: promote the execution to ready without taking a semaphore slot, so the job fails on execution with a proper NameError and becomes visible as a failed execution instead of wedging the dispatcher. Fixes #784
1 parent 6816e52 commit 3deff3d

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎app/models/solid_queue/blocked_execution.rb‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ def set_expires_at
6262
end
6363

6464
def acquire_concurrency_lock
65+
# A job whose class no longer resolves can't check its concurrency limits, but it
66+
# can't hold a semaphore either. Release it without one so it fails on execution
67+
# instead of crashing the dispatcher's concurrency maintenance forever.
68+
return true unless job.concurrency_limited?
69+
6570
Semaphore.wait(job)
6671
end
6772

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
class SolidQueue::BlockedExecutionTest < ActiveSupport::TestCase
6+
self.use_transactional_tests = false
7+
8+
class NonOverlappingJob < ApplicationJob
9+
limits_concurrency key: ->(job_result, **) { job_result }
10+
11+
def perform(job_result)
12+
end
13+
end
14+
15+
setup do
16+
@result = JobResult.create!(queue_name: "default")
17+
end
18+
19+
test "release a blocked execution whose job class no longer resolves" do
20+
NonOverlappingJob.perform_later(@result)
21+
NonOverlappingJob.perform_later(@result)
22+
23+
blocked_job = SolidQueue::Job.last
24+
assert blocked_job.blocked?
25+
26+
# Simulate the job class being renamed or deleted in a later deploy
27+
SolidQueue::Job.where(id: blocked_job.id).update_all(class_name: "NoLongerExistingJob")
28+
semaphore_value = SolidQueue::Semaphore.find_by!(key: blocked_job.concurrency_key).value
29+
30+
assert SolidQueue::BlockedExecution.release_one(blocked_job.concurrency_key)
31+
32+
# The execution is promoted to ready, where it will fail on execution and
33+
# be recorded as failed, instead of being retried by the dispatcher forever
34+
assert_not SolidQueue::BlockedExecution.exists?(job_id: blocked_job.id)
35+
assert SolidQueue::ReadyExecution.exists?(job_id: blocked_job.id)
36+
37+
# Without concurrency limits to check, no semaphore slot is taken
38+
assert_equal semaphore_value, SolidQueue::Semaphore.find_by!(key: blocked_job.concurrency_key).value
39+
end
40+
end

0 commit comments

Comments
 (0)