1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Merge pull request #2285 from eugenk/2284-handle_circular_error_causes

Handle circular error causes
This commit is contained in:
Abdelkader Boudih 2015-04-08 18:48:23 +01:00
commit 7c9b1594ea
2 changed files with 46 additions and 2 deletions

View file

@ -188,12 +188,16 @@ module Sidekiq
end end
end end
def exception_caused_by_shutdown?(e) def exception_caused_by_shutdown?(e, checked_causes = [])
# In Ruby 2.1.0 only, check if exception is a result of shutdown. # In Ruby 2.1.0 only, check if exception is a result of shutdown.
return false unless defined?(e.cause) return false unless defined?(e.cause)
# Handle circular causes
checked_causes << e.object_id
return false if checked_causes.include?(e.cause.object_id)
e.cause.instance_of?(Sidekiq::Shutdown) || e.cause.instance_of?(Sidekiq::Shutdown) ||
exception_caused_by_shutdown?(e.cause) exception_caused_by_shutdown?(e.cause, checked_causes)
end end
end end

View file

@ -328,6 +328,46 @@ class TestRetry < Sidekiq::Test
File.read(@tmp_log_path), 'Log entry missing for sidekiq_retry_in') File.read(@tmp_log_path), 'Log entry missing for sidekiq_retry_in')
end end
end end
describe 'handles errors withouth cause' do
before do
@error = nil
begin
raise ::StandardError, 'Error'
rescue ::StandardError => e
@error = e
end
end
it "does not recurse infinitely checking if it's a shutdown" do
assert(!Sidekiq::Middleware::Server::RetryJobs.new.send(
:exception_caused_by_shutdown?, @error))
end
end
describe 'handles errors with circular causes' do
before do
@error = nil
begin
begin
raise ::StandardError, 'Error 1'
rescue ::StandardError => e1
begin
raise ::StandardError, 'Error 2'
rescue ::StandardError => e2
raise e1
end
end
rescue ::StandardError => e
@error = e
end
end
it "does not recurse infinitely checking if it's a shutdown" do
assert(!Sidekiq::Middleware::Server::RetryJobs.new.send(
:exception_caused_by_shutdown?, @error))
end
end
end end
end end