Skip to content

Commit

Permalink
Proper stopping of strategy on replicaset stop
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed Sep 8, 2012
1 parent 1bdfc16 commit 01a4ded
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lib/mongodb/connection/repl_set.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,9 @@ ReplSet.prototype.close = function(callback) {
}
}

// If we have a strategy stop it
if(this.strategyInstance) this.strategyInstance.stop();

// If it's a callback
if(typeof callback == 'function') callback(null, null);
}
Expand Down
12 changes: 6 additions & 6 deletions lib/mongodb/connection/strategies/ping_strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ PingStrategy.prototype._pingServer = function(callback) {
// Ping server function
var pingFunction = function() {
if(self.state == 'disconnected') return;

var addresses = self.replicaset._state.addresses;

// Grab all servers
Expand All @@ -150,8 +149,8 @@ PingStrategy.prototype._pingServer = function(callback) {
db.on("error", done);

// Open the db instance
db.open(function(err) {
if (err) return done();
db.open(function(err, _db) {
if(err) return done(_db);

// Startup time of the command
var startTime = Date.now();
Expand All @@ -161,13 +160,14 @@ PingStrategy.prototype._pingServer = function(callback) {
if(null != serverInstance.runtimeStats && serverInstance.isConnected()) {
serverInstance.runtimeStats['pingMs'] = Date.now() - startTime;
}
done();

done(_db);
})
})

function done () {
function done (_db) {
// Close connection
db.close();
_db.close(true);

// Adjust the number of checks
numberOfEntries--;
Expand Down

0 comments on commit 01a4ded

Please sign in to comment.