Skip to content

Commit c8f5776

Browse files
committed
Ensure timeout works correctly #1032
1 parent d48c4ed commit c8f5776

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/mongodb/connection/server.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,18 @@ Server.prototype.connect = function(dbInstance, options, callback) {
623623
// Emit error
624624
server._emitAcrossAllDbInstances(server, eventReceiver, "timeout", err, server, true);
625625
}
626+
627+
// If we have autoConnect enabled let's fire up an attempt to reconnect
628+
if(server.isAutoReconnect()
629+
&& !server.isSetMember()
630+
&& (server._serverState != 'destroyed')
631+
&& !server._reconnectInProgreess) {
632+
// Set the number of retries
633+
server._reconnect_retries = server.db.numberOfRetries;
634+
// Attempt reconnect
635+
server._reconnectInProgreess = true;
636+
setTimeout(__attemptReconnect(server), server.db.retryMiliSeconds);
637+
}
626638
});
627639

628640
// Handle errors

test/tools/replica_set_manager.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ ReplicaSetManager.prototype.addSecondary = function(options, callback) {
576576
// Get the configuration
577577
var connection = new Db("local", new Server(primary.split(":")[0], parseInt(primary.split(":")[1], 10), {
578578
ssl:self.ssl
579-
, auto_reconnect:true
579+
, auto_reconnect:false
580580
, poolSize:1
581581
, socketOptions: {
582582
connectTimeoutMS: 30000
@@ -689,7 +689,7 @@ ReplicaSetManager.prototype.getConnection = function(node, callback) {
689689
var intervalId = setInterval(function() {
690690
var connection = new Db("replicaset_test", new Server(self.host, self.mongods[node]["port"], {
691691
ssl:self.ssl
692-
, auto_reconnect:true
692+
, auto_reconnect:false
693693
, socketOptions: {
694694
connectTimeoutMS: 30000
695695
, socketTimeoutMS: 30000
@@ -745,7 +745,7 @@ ReplicaSetManager.prototype.reStartAndConfigure = function(node_configs, callbac
745745
// Get the configuration
746746
var connection = new Db("local", new Server(primary.split(":")[0], parseInt(primary.split(":")[1], 10), {
747747
ssl:self.ssl
748-
, auto_reconnect:true
748+
, auto_reconnect:false
749749
, socketOptions: {
750750
connectTimeoutMS: 30000
751751
, socketTimeoutMS: 30000

0 commit comments

Comments
 (0)