Skip to content

Commit b9d9469

Browse files
committed
Merge pull request #275 from amutake/fix-future-deadlock
Fix deadlock of Future when the handler raises Exception
2 parents bf6e2b5 + f1a66d8 commit b9d9469

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/concurrent/future.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def self.execute(opts = {}, &block)
8282

8383
# @!visibility private
8484
def work # :nodoc:
85-
success, val, reason = SafeTaskExecutor.new(@task).execute(*@args)
85+
success, val, reason = SafeTaskExecutor.new(@task, rescue_exception: true).execute(*@args)
8686
complete(success, val, reason)
8787
end
8888
end

spec/concurrent/future_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ def trigger_observable(observable)
204204
expect(future.value).to be_nil
205205
end
206206

207+
it 'sets the value to nil when the handler raises Exception' do
208+
future = Future.new(executor: executor){ raise Exception }.execute
209+
expect(future.value).to be_nil
210+
end
211+
212+
it 'sets the reason to the Exception instance when the handler raises Exception' do
213+
future = Future.new(executor: executor){ raise Exception }.execute
214+
expect(future.reason).to be_a(Exception)
215+
end
216+
207217
it 'sets the state to :rejected when the handler raises an exception' do
208218
future = Future.new(executor: executor){ raise StandardError }.execute
209219
expect(future).to be_rejected

0 commit comments

Comments
 (0)