RUBY-386 set 30 second connect timeout. Fail if ismaster fails.
This commit is contained in:
parent
4ed709ff7f
commit
c308f9b025
@ -52,7 +52,7 @@ module Mongo
|
||||
# this is the number of seconds to wait for a new connection to be released before throwing an exception.
|
||||
# Note: this setting is relevant only for multi-threaded applications.
|
||||
# @option opts [Float] :op_timeout (30) The number of seconds to wait for a read operation to time out.
|
||||
# @option opts [Float] :connect_timeout (nil) The number of seconds to wait before timing out a
|
||||
# @option opts [Float] :connect_timeout (30) The number of seconds to wait before timing out a
|
||||
# connection attempt.
|
||||
# @option opts [Boolean] :ssl (false) If true, create the connection to the server using SSL.
|
||||
# @option opts [Boolean] :refresh_mode (false) Set this to :sync to periodically update the
|
||||
@ -472,7 +472,7 @@ module Mongo
|
||||
@op_timeout = opts[:op_timeout] || 30
|
||||
|
||||
# Timeout on socket connect.
|
||||
@connect_timeout = opts[:connect_timeout] || nil
|
||||
@connect_timeout = opts[:connect_timeout] || 30
|
||||
|
||||
# Mutex for synchronizing pool access
|
||||
# TODO: remove this.
|
||||
|
@ -84,7 +84,13 @@ module Mongo
|
||||
# matches with the name provided.
|
||||
def set_config
|
||||
begin
|
||||
@config = @connection['admin'].command({:ismaster => 1}, :socket => @socket)
|
||||
if @connection.connect_timeout
|
||||
Mongo::TimeoutHandler.timeout(@connection.connect_timeout, OperationTimeout) do
|
||||
@config = @connection['admin'].command({:ismaster => 1}, :socket => @socket)
|
||||
end
|
||||
else
|
||||
@config = @connection['admin'].command({:ismaster => 1}, :socket => @socket)
|
||||
end
|
||||
|
||||
if @config['msg'] && @logger
|
||||
@connection.log(:warn, "#{config['msg']}")
|
||||
@ -95,6 +101,7 @@ module Mongo
|
||||
rescue ConnectionFailure, OperationFailure, OperationTimeout, SocketError, SystemCallError, IOError => ex
|
||||
@connection.log(:warn, "Attempted connection to node #{host_string} raised " +
|
||||
"#{ex.class}: #{ex.message}")
|
||||
@socket.close unless @socket.closed?
|
||||
return nil
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user