RUBY-416 do not checkout closed sockets

This commit is contained in:
Tyler Brock 2012-03-07 12:00:10 -05:00
parent 8c3283f514
commit 06bc50fe46
3 changed files with 18 additions and 4 deletions

View File

@ -470,7 +470,7 @@ module Mongo
Mongo::Constants::OP_QUERY, message, nil, sock, @command,
nil, @options & OP_QUERY_EXHAUST != 0)
rescue ConnectionFailure, OperationFailure, OperationTimeout => ex
force_checkin_socket(sock)
force_checkin_socket(sock) unless @socket
raise ex
end
checkin_socket(sock) unless @socket

View File

@ -355,7 +355,7 @@ module Mongo
# Checkin a socket used for reading.
def checkin_reader(socket)
if socket && socket.pool
if socket
socket.pool.checkin(socket)
end
sync_refresh
@ -363,7 +363,7 @@ module Mongo
# Checkin a socket used for writing.
def checkin_writer(socket)
if socket && socket.pool
if socket
socket.pool.checkin(socket)
end
sync_refresh

View File

@ -19,7 +19,7 @@ module Mongo
class Pool
PING_ATTEMPTS = 6
MAX_PING_TIME = 1_000_000
PRUNE_INTERVAL = 1000
PRUNE_INTERVAL = 10000
attr_accessor :host, :port, :address,
:size, :timeout, :safe, :checked_out, :connection
@ -66,6 +66,7 @@ module Mongo
def close(opts={})
@connection_mutex.synchronize do
if opts[:soft] && !@checked_out.empty?
@closing = true
close_sockets(@sockets - @checked_out)
else
close_sockets(@sockets)
@ -282,6 +283,18 @@ module Mongo
op.call
end
if socket.closed?
@checked_out.delete(socket)
@sockets.delete(socket)
@threads_to_sockets.each do |k,v|
if v == socket
@threads_to_sockets.delete(k)
end
end
socket = checkout_new_socket
end
return socket
else
# Otherwise, wait
@ -295,6 +308,7 @@ module Mongo
def close_sockets(sockets)
sockets.each do |socket|
@sockets.delete(socket)
begin
socket.close unless socket.closed?
rescue IOError => ex