Skip to content

Commit a4b19d4

Browse files
kemperdefunkt
authored andcommitted
fixed a defect where exceptions in the failure backend would cause the chile process to terminate like the parent
1 parent 5765fe1 commit a4b19d4

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

lib/resque/worker.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ def perform(job)
162162
job.perform
163163
rescue Object => e
164164
log "#{job.inspect} failed: #{e.inspect}"
165-
job.fail(e)
165+
begin
166+
job.fail(e)
167+
rescue Object => e
168+
log "Received exception when reporting failure: #{e.inspect}"
169+
end
166170
failed!
167171
else
168172
log "done: #{job.inspect}"

test/test_helper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,17 @@ def self.perform
114114
raise SyntaxError, "Extra Bad job!"
115115
end
116116
end
117+
118+
class BadFailureBackend < Resque::Failure::Base
119+
def save
120+
raise Exception.new("Failure backend error")
121+
end
122+
end
123+
124+
def with_failure_backend(failure_backend, &block)
125+
previous_backend = Resque::Failure.backend
126+
Resque::Failure.backend = failure_backend
127+
yield block
128+
ensure
129+
Resque::Failure.backend = previous_backend
130+
end

test/worker_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
assert_equal('Extra Bad job!', Resque::Failure.all['error'])
2626
end
2727

28+
test "does not allow exceptions from failure backend to escape" do
29+
job = Resque::Job.new(:jobs, {})
30+
with_failure_backend BadFailureBackend do
31+
@worker.perform job
32+
end
33+
end
34+
2835
test "fails uncompleted jobs on exit" do
2936
job = Resque::Job.new(:jobs, [GoodJob, "blah"])
3037
@worker.working_on(job)

0 commit comments

Comments
 (0)