Distinguish between hard and soft pool close.

This commit is contained in:
Kyle Banker 2011-11-04 09:23:41 -04:00
parent 3e2c4c3851
commit a2a307c45d
3 changed files with 13 additions and 6 deletions

View File

@ -496,10 +496,8 @@ module Mongo
# Used to close, check in, or refresh sockets held
# in thread-local variables.
def local_socket_done(socket)
puts "Done. Threads: #{Thread.list.size}, pool_size: #{self.pool_size}"
if self.connections[self.object_id][:reader] == socket
if self.read_pool.sockets_low?
puts "***SOCKETS ARE LOW! READER****"
checkin(socket)
self.connections[self.object_id][:reader] = nil
end
@ -507,7 +505,6 @@ module Mongo
if self.connections[self.object_id][:writer] == socket
if self.primary_pool && self.primary_pool.sockets_low?
puts "***SOCKETS ARE LOW! WRITER****"
checkin(socket)
self.connections[self.object_id][:writer] = nil
end

View File

@ -207,7 +207,9 @@ module Mongo
background_manager.connect
# TODO: make sure that connect has succeeded
old_manager = @manager
update_config(background_manager)
old_manager.close(:soft => true)
initiate_refresh_mode
return true
@ -516,7 +518,6 @@ module Mongo
@seeds = @manager.seeds.dup
@sockets_to_pools.clear
@refresh_version += 1
old_manager.close if old_manager
end
# If we're using async refresh, start

View File

@ -59,9 +59,18 @@ module Mongo
@closed = false
end
def close
# Close this pool.
#
# @option opts [Boolean] :soft (false) If true,
# close only those sockets that are not checked out.
def close(opts={})
@connection_mutex.synchronize do
(@sockets - @checked_out).each do |sock|
if opts[:soft]
sockets_to_close = @sockets - @checked_out
else
sockets_to_close = @sockets
end
sockets_to_close.each do |sock|
begin
sock.close
rescue IOError => ex