Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Destroy connection on socket timeout due to newer node versions not c…
Browse files Browse the repository at this point in the history
…losing the socket. Updated version to 2.0.6
  • Loading branch information
christkv committed Jul 19, 2016
1 parent ea0de70 commit 0860eb4
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
4 changes: 4 additions & 0 deletions HISTORY.md
@@ -1,3 +1,7 @@
2.0.6 2016-07-19
----------------
* Destroy connection on socket timeout due to newer node versions not closing the socket.

2.0.5 2016-07-15
----------------
* Minor fixes to handle faster MongoClient connectivity from the driver, allowing single server instances to detect if they are a proxy.
Expand Down
7 changes: 7 additions & 0 deletions lib/connection/pool.js
Expand Up @@ -211,6 +211,10 @@ function reauthenticate(pool, connection, cb) {

function connectionFailureHandler(self, event) {
return function(err) {
// Destroy the connection
this.destroy();

// Remove the connection
removeConnection(self, this);

// Flush out the callback if there is one
Expand Down Expand Up @@ -268,6 +272,9 @@ function attemptReconnect(self) {
// If we have failure schedule a retry
function _connectionFailureHandler(self, event) {
return function() {
// Destroy the connection
this.destroy();
// Count down the number of reconnects
self.retriesLeft = self.retriesLeft - 1;
// How many retries are left
if(self.retriesLeft == 0) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "mongodb-core",
"version": "2.0.5",
"version": "2.0.6",
"description": "Core MongoDB driver functionality, no bells and whistles and meant for integration not end applications",
"main": "index.js",
"scripts": {
Expand Down
72 changes: 72 additions & 0 deletions test1.js
@@ -0,0 +1,72 @@
var Server = require('./lib/topologies/server');

// Attempt to connect
var server = new Server({
host: 'localhost', port: 27017, socketTimeout: 500
});

// function executeCursors(_server, cb) {
// var count = 100;
//
// for(var i = 0; i < 100; i++) {
// // Execute the write
// var cursor = _server.cursor('test.test', {
// find: 'test.test'
// , query: {a:1}
// }, {readPreference: new ReadPreference('secondary')});
//
// // Get the first document
// cursor.next(function(err, doc) {
// count = count - 1;
// if(err) console.dir(err)
// if(count == 0) return cb();
// });
// }
// }

server.on('connect', function(_server) {

setInterval(function() {
_server.insert('test.test', [{a:1}], function(err, r) {
console.log("insert")
});
}, 1000)
// console.log("---------------------------------- 0")
// // Attempt authentication
// _server.auth('scram-sha-1', 'admin', 'root', 'root', function(err, r) {
// console.log("---------------------------------- 1")
// // console.dir(err)
// // console.dir(r)
//
// _server.insert('test.test', [{a:1}], function(err, r) {
// console.log("---------------------------------- 2")
// console.dir(err)
// if(r)console.dir(r.result)
// var name = null;
//
// _server.on('joined', function(_t, _server) {
// if(name == _server.name) {
// console.log("=========== joined :: " + _t + " :: " + _server.name)
// executeCursors(_server, function() {
// });
// }
// })
//
// // var s = _server.s.replicaSetState.secondaries[0];
// // s.destroy({emitClose:true});
// executeCursors(_server, function() {
// console.log("============== 0")
// // Attempt to force a server reconnect
// var s = _server.s.replicaSetState.secondaries[0];
// name = s.name;
// s.destroy({emitClose:true});
// // console.log("============== 1")
//
// // _server.destroy();
// // test.done();
// });
// });
// });
});

server.connect();

0 comments on commit 0860eb4

Please sign in to comment.