File tree 2 files changed +20
-2
lines changed
lib/concurrent-ruby/concurrent/executor
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 3
3
require 'concurrent/collection/non_concurrent_priority_queue'
4
4
require 'concurrent/executor/executor_service'
5
5
require 'concurrent/executor/single_thread_executor'
6
-
6
+ require 'concurrent/errors'
7
7
require 'concurrent/options'
8
8
9
9
module Concurrent
@@ -162,7 +162,11 @@ def process_tasks
162
162
# queue now must have the same pop time, or a closer one, as
163
163
# when we peeked).
164
164
task = synchronize { @queue . pop }
165
- task . executor . post { task . process_task }
165
+ begin
166
+ task . executor . post { task . process_task }
167
+ rescue RejectedExecutionError
168
+ # ignore and continue
169
+ end
166
170
else
167
171
@condition . wait ( [ diff , 60 ] . min )
168
172
end
Original file line number Diff line number Diff line change @@ -122,6 +122,20 @@ module Concurrent
122
122
expect ( task . value ) . to eq i
123
123
end
124
124
end
125
+
126
+ it 'safely handles an executor raising RejectedExecutionError' do
127
+ # force a task's executor to raise RejectedExecutionError within the TimerSet
128
+ abort_executor = ImmediateExecutor . new
129
+ allow ( abort_executor ) . to receive ( :post ) . and_raise ( Concurrent ::RejectedExecutionError )
130
+ ScheduledTask . execute ( 0.2 , executor : abort_executor , timer_set : subject ) { nil }
131
+ abort_executor . shutdown
132
+
133
+ latch = CountDownLatch . new ( 1 )
134
+ ScheduledTask . execute ( 0.3 , timer_set : subject ) do
135
+ latch . count_down
136
+ end
137
+ expect ( latch . wait ( 1 ) ) . to be_truthy
138
+ end
125
139
end
126
140
127
141
context 'resolution' do
You can’t perform that action at this time.
0 commit comments