ruby-concurrency/concurrent-ruby

ThreadPoolExecutor#kill: documentation and implementation are out of sync

Opened this issue · 0 comments

hms commented
* Operating system:                mac
* Ruby implementation:             Ruby
* `concurrent-ruby` version:       1.3.4
* `concurrent-ruby-ext` installed: no
* `concurrent-ruby-edge` used:     no

The docs for ThreadPoolExecutor#kill suggest that inflight tasks will run to completion.

#kill

Begin an immediate shutdown. In-progress tasks will be allowed to complete but enqueued tasks will be dismissed and no new tasks will be accepted. Has no additional effect if the thread pool is not running.

This (maybe too) simple test suggests the Executor will kill its internal threads and not allow them to finish.

e = Concurrent::ThreadPoolExecutor.new
f = Concurrent::Promises.future_on(e) { sleep 10; puts "I'm alive!" }
sleep 11
I'm alive!
f = Concurrent::Promises.future_on(e) { sleep 10; puts "I'm alive!" }
e.kill
e.shutdown? => true
# future f never completes

The code for #kill in ruby_executor_service.rb:

def kill
  synchronize do
     break if shutdown?
     stop_event.set
     ns_kill_execution 
     stopped_event.set
   end
   true
 end

ns_kill_execution:

def ns_kill_execution
 # TODO log out unprocessed tasks in queue
 # TODO try to shutdown first?
 @pool.each(&:kill)
 @pool.clear
 @ready.clear
end

and @pool.each(&:kill) concludes with:

def kill
  @thread.kill
end