diff --git a/lib/mongo/util/pool.rb b/lib/mongo/util/pool.rb index a6e721a..f28ca08 100644 --- a/lib/mongo/util/pool.rb +++ b/lib/mongo/util/pool.rb @@ -227,15 +227,10 @@ module Mongo end def prune_thread_socket_hash - map = {} - Thread.list.each do |t| - map[t] = 1 - end + current_threads = Set[*Thread.list] - @threads_to_sockets.keys.each do |key| - if !map[key] - @threads_to_sockets.delete(key) - end + @threads_to_sockets.delete_if do |thread, socket| + !current_threads.include?(thread) end end diff --git a/test/pool_test.rb b/test/pool_test.rb index 0a5830d..a62f69e 100644 --- a/test/pool_test.rb +++ b/test/pool_test.rb @@ -12,12 +12,10 @@ class PoolTest < Test::Unit::TestCase @pool = Pool.new(@connection, TEST_HOST, TEST_PORT, :size => 5) @threads = [] - @sockets = [] 10.times do @threads << Thread.new do original_socket = @pool.checkout - @sockets << original_socket @pool.checkin(original_socket) 5000.times do socket = @pool.checkout