Skip to content

Commit 4ed709f

Browse files
committed
RUBY-386 ensure that replica set connection doesn't hang when
connecting to unreponsive node. set default op timeout to 30 seconds.
1 parent ec97bd0 commit 4ed709f

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

lib/mongo/repl_set_connection.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ class ReplSetConnection < Connection
5151
# @option options [Float] :pool_timeout (5.0) When all of the connections a pool are checked out,
5252
# this is the number of seconds to wait for a new connection to be released before throwing an exception.
5353
# Note: this setting is relevant only for multi-threaded applications.
54-
# @option opts [Float] :op_timeout (nil) The number of seconds to wait for a read operation to time out.
55-
# Disabled by default.
54+
# @option opts [Float] :op_timeout (30) The number of seconds to wait for a read operation to time out.
5655
# @option opts [Float] :connect_timeout (nil) The number of seconds to wait before timing out a
5756
# connection attempt.
5857
# @option opts [Boolean] :ssl (false) If true, create the connection to the server using SSL.
@@ -470,7 +469,7 @@ def setup(opts)
470469
@pool_timeout = opts[:pool_timeout] || opts[:timeout] || 5.0
471470

472471
# Timeout on socket read operation.
473-
@op_timeout = opts[:op_timeout] || nil
472+
@op_timeout = opts[:op_timeout] || 30
474473

475474
# Timeout on socket connect.
476475
@connect_timeout = opts[:connect_timeout] || nil

lib/mongo/util/node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def set_config
9292

9393
check_set_membership(config)
9494
check_set_name(config)
95-
rescue ConnectionFailure, OperationFailure, SocketError, SystemCallError, IOError => ex
95+
rescue ConnectionFailure, OperationFailure, OperationTimeout, SocketError, SystemCallError, IOError => ex
9696
@connection.log(:warn, "Attempted connection to node #{host_string} raised " +
9797
"#{ex.class}: #{ex.message}")
9898
return nil

0 commit comments

Comments
 (0)