RUBY-416 do not checkout closed sockets
This commit is contained in:
parent
8c3283f514
commit
06bc50fe46
|
@ -470,7 +470,7 @@ module Mongo
|
||||||
Mongo::Constants::OP_QUERY, message, nil, sock, @command,
|
Mongo::Constants::OP_QUERY, message, nil, sock, @command,
|
||||||
nil, @options & OP_QUERY_EXHAUST != 0)
|
nil, @options & OP_QUERY_EXHAUST != 0)
|
||||||
rescue ConnectionFailure, OperationFailure, OperationTimeout => ex
|
rescue ConnectionFailure, OperationFailure, OperationTimeout => ex
|
||||||
force_checkin_socket(sock)
|
force_checkin_socket(sock) unless @socket
|
||||||
raise ex
|
raise ex
|
||||||
end
|
end
|
||||||
checkin_socket(sock) unless @socket
|
checkin_socket(sock) unless @socket
|
||||||
|
|
|
@ -355,7 +355,7 @@ module Mongo
|
||||||
|
|
||||||
# Checkin a socket used for reading.
|
# Checkin a socket used for reading.
|
||||||
def checkin_reader(socket)
|
def checkin_reader(socket)
|
||||||
if socket && socket.pool
|
if socket
|
||||||
socket.pool.checkin(socket)
|
socket.pool.checkin(socket)
|
||||||
end
|
end
|
||||||
sync_refresh
|
sync_refresh
|
||||||
|
@ -363,7 +363,7 @@ module Mongo
|
||||||
|
|
||||||
# Checkin a socket used for writing.
|
# Checkin a socket used for writing.
|
||||||
def checkin_writer(socket)
|
def checkin_writer(socket)
|
||||||
if socket && socket.pool
|
if socket
|
||||||
socket.pool.checkin(socket)
|
socket.pool.checkin(socket)
|
||||||
end
|
end
|
||||||
sync_refresh
|
sync_refresh
|
||||||
|
|
|
@ -19,7 +19,7 @@ module Mongo
|
||||||
class Pool
|
class Pool
|
||||||
PING_ATTEMPTS = 6
|
PING_ATTEMPTS = 6
|
||||||
MAX_PING_TIME = 1_000_000
|
MAX_PING_TIME = 1_000_000
|
||||||
PRUNE_INTERVAL = 1000
|
PRUNE_INTERVAL = 10000
|
||||||
|
|
||||||
attr_accessor :host, :port, :address,
|
attr_accessor :host, :port, :address,
|
||||||
:size, :timeout, :safe, :checked_out, :connection
|
:size, :timeout, :safe, :checked_out, :connection
|
||||||
|
@ -66,6 +66,7 @@ module Mongo
|
||||||
def close(opts={})
|
def close(opts={})
|
||||||
@connection_mutex.synchronize do
|
@connection_mutex.synchronize do
|
||||||
if opts[:soft] && !@checked_out.empty?
|
if opts[:soft] && !@checked_out.empty?
|
||||||
|
@closing = true
|
||||||
close_sockets(@sockets - @checked_out)
|
close_sockets(@sockets - @checked_out)
|
||||||
else
|
else
|
||||||
close_sockets(@sockets)
|
close_sockets(@sockets)
|
||||||
|
@ -282,6 +283,18 @@ module Mongo
|
||||||
op.call
|
op.call
|
||||||
end
|
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
|
return socket
|
||||||
else
|
else
|
||||||
# Otherwise, wait
|
# Otherwise, wait
|
||||||
|
@ -295,6 +308,7 @@ module Mongo
|
||||||
|
|
||||||
def close_sockets(sockets)
|
def close_sockets(sockets)
|
||||||
sockets.each do |socket|
|
sockets.each do |socket|
|
||||||
|
@sockets.delete(socket)
|
||||||
begin
|
begin
|
||||||
socket.close unless socket.closed?
|
socket.close unless socket.closed?
|
||||||
rescue IOError => ex
|
rescue IOError => ex
|
||||||
|
|
Loading…
Reference in New Issue