RUBY-231 RUBY-250 Validate socket against pid
This commit is contained in:
parent
a8ce896c9f
commit
997d9b8ae2
|
@ -41,6 +41,7 @@ module Mongo
|
|||
@socket_ops = Hash.new { |h, k| h[k] = [] }
|
||||
|
||||
@sockets = []
|
||||
@pids = {}
|
||||
@checked_out = []
|
||||
end
|
||||
|
||||
|
@ -54,6 +55,7 @@ module Mongo
|
|||
end
|
||||
@host = @port = nil
|
||||
@sockets.clear
|
||||
@pids.clear
|
||||
@checked_out.clear
|
||||
end
|
||||
|
||||
|
@ -83,6 +85,7 @@ module Mongo
|
|||
@connection.apply_saved_authentication(:socket => socket)
|
||||
|
||||
@sockets << socket
|
||||
@pids[socket] = Process.pid
|
||||
@checked_out << socket
|
||||
socket
|
||||
end
|
||||
|
@ -115,13 +118,23 @@ module Mongo
|
|||
|
||||
# Checks out the first available socket from the pool.
|
||||
#
|
||||
# If the pid has changed, remove the socket and check out
|
||||
# new one.
|
||||
#
|
||||
# This method is called exclusively from #checkout;
|
||||
# therefore, it runs within a mutex.
|
||||
def checkout_existing_socket
|
||||
socket = (@sockets - @checked_out).first
|
||||
if @pids[socket] != Process.pid
|
||||
@pids[socket] = nil
|
||||
@sockets.delete(socket)
|
||||
socket.close
|
||||
checkout_new_socket
|
||||
else
|
||||
@checked_out << socket
|
||||
socket
|
||||
end
|
||||
end
|
||||
|
||||
# Check out an existing socket or create a new socket if the maximum
|
||||
# pool size has not been exceeded. Otherwise, wait for the next
|
||||
|
|
|
@ -220,6 +220,7 @@ class TestConnection < Test::Unit::TestCase
|
|||
|
||||
conn.primary_pool.host = 'localhost'
|
||||
conn.primary_pool.port = Mongo::Connection::DEFAULT_PORT
|
||||
conn.primary_pool.instance_variable_set("@pids", {dropped_socket => Process.pid})
|
||||
conn.primary_pool.instance_variable_set("@sockets", [dropped_socket])
|
||||
|
||||
assert !conn.active?
|
||||
|
|
Loading…
Reference in New Issue