From 0860eb4ed58155f9e4a5fb7212b93e27cf10f5a2 Mon Sep 17 00:00:00 2001 From: Christian Kvalheim Date: Tue, 19 Jul 2016 03:09:51 +0200 Subject: [PATCH] Destroy connection on socket timeout due to newer node versions not closing the socket. Updated version to 2.0.6 --- HISTORY.md | 4 +++ lib/connection/pool.js | 7 ++++ package.json | 2 +- test1.js | 72 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 test1.js diff --git a/HISTORY.md b/HISTORY.md index e1b7a7200..b99f6f54b 100644 --- a/HISTORY.md +++ b/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. diff --git a/lib/connection/pool.js b/lib/connection/pool.js index 4f1c83b9d..96ae4cede 100644 --- a/lib/connection/pool.js +++ b/lib/connection/pool.js @@ -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 @@ -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) { diff --git a/package.json b/package.json index 7e0ad78fd..e8e734e66 100644 --- a/package.json +++ b/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": { diff --git a/test1.js b/test1.js new file mode 100644 index 000000000..6e05ebd55 --- /dev/null +++ b/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();