Skip to content

Commit f514ea9

Browse files
committed
Fix #173 leaking threads when pruning the pool
1 parent 2710c43 commit f514ea9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/concurrent/executor/ruby_thread_pool_executor.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,11 @@ def handle_overflow(*args)
254254
# @!visibility private
255255
def prune_pool
256256
if Time.now.to_f - @gc_interval >= @last_gc_time
257-
@pool.delete_if do |worker|
258-
worker.dead? ||
259-
(@idletime == 0 ? false : Time.now.to_f - @idletime > worker.last_activity)
260-
end
257+
@pool.delete_if { |worker| worker.dead? }
258+
# send :stop for each thread over idletime
259+
@pool.
260+
select { |worker| @idletime != 0 && Time.now.to_f - @idletime > worker.last_activity }.
261+
each { @queue << :stop }
261262
@last_gc_time = Time.now.to_f
262263
end
263264
end

0 commit comments

Comments
 (0)