mongodb-core
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -0,1 +1,16 @@ | ||
<a name="3.1.2"></a> | ||
## [3.1.2](https://github.com/mongodb-js/mongodb-core/compare/v3.1.1...v3.1.2) (2018-08-13) | ||
### Bug Fixes | ||
* **mongos:** fix connection leak when mongos reconnects ([2453746](https://github.com/mongodb-js/mongodb-core/commit/2453746)) | ||
### Features | ||
* **bson:** update to bson ^1.1.x ([952a2f0](https://github.com/mongodb-js/mongodb-core/commit/952a2f0)) | ||
<a name="3.1.1"></a> | ||
@@ -2,0 +17,0 @@ ## [3.1.1](https://github.com/mongodb-js/mongodb-core/compare/v3.0.6...v3.1.1) (2018-08-13) |
@@ -591,70 +591,3 @@ 'use strict'; | ||
if (!self.cursorState.init) { | ||
// Topology is not connected, save the call in the provided store to be | ||
// Executed at some point when the handler deems it's reconnected | ||
if (!self.topology.isConnected(self.options)) { | ||
// Only need this for single server, because repl sets and mongos | ||
// will always continue trying to reconnect | ||
if (self.topology._type === 'server' && !self.topology.s.options.reconnect) { | ||
// Reconnect is disabled, so we'll never reconnect | ||
return callback(new MongoError('no connection available')); | ||
} | ||
if (self.disconnectHandler != null) { | ||
if (self.topology.isDestroyed()) { | ||
// Topology was destroyed, so don't try to wait for it to reconnect | ||
return callback(new MongoError('Topology was destroyed')); | ||
} | ||
return self.disconnectHandler.addObjectAndMethod( | ||
'cursor', | ||
self, | ||
'next', | ||
[callback], | ||
callback | ||
); | ||
} | ||
} | ||
try { | ||
self.server = self.topology.getServer(self.options); | ||
} catch (err) { | ||
// Handle the error and add object to next method call | ||
if (self.disconnectHandler != null) { | ||
return self.disconnectHandler.addObjectAndMethod( | ||
'cursor', | ||
self, | ||
'next', | ||
[callback], | ||
callback | ||
); | ||
} | ||
// Otherwise return the error | ||
return callback(err); | ||
} | ||
// Set as init | ||
self.cursorState.init = true; | ||
// error if collation not supported | ||
if (collationNotSupported(self.server, self.cmd)) { | ||
return callback(new MongoError(`server ${self.server.name} does not support collation`)); | ||
} | ||
try { | ||
self.query = self.server.wireProtocolHandler.command( | ||
self.bson, | ||
self.ns, | ||
self.cmd, | ||
self.cursorState, | ||
self.topology, | ||
self.options | ||
); | ||
if (self.query instanceof MongoError) { | ||
return callback(self.query); | ||
} | ||
} catch (err) { | ||
return callback(err); | ||
} | ||
return initializeCursor(self, callback); | ||
} | ||
@@ -820,2 +753,77 @@ | ||
function initializeCursor(cursor, callback) { | ||
// Topology is not connected, save the call in the provided store to be | ||
// Executed at some point when the handler deems it's reconnected | ||
if (!cursor.topology.isConnected(cursor.options)) { | ||
// Only need this for single server, because repl sets and mongos | ||
// will always continue trying to reconnect | ||
if (cursor.topology._type === 'server' && !cursor.topology.s.options.reconnect) { | ||
// Reconnect is disabled, so we'll never reconnect | ||
return callback(new MongoError('no connection available')); | ||
} | ||
if (cursor.disconnectHandler != null) { | ||
if (cursor.topology.isDestroyed()) { | ||
// Topology was destroyed, so don't try to wait for it to reconnect | ||
return callback(new MongoError('Topology was destroyed')); | ||
} | ||
return cursor.disconnectHandler.addObjectAndMethod( | ||
'cursor', | ||
cursor, | ||
'next', | ||
[callback], | ||
callback | ||
); | ||
} | ||
} | ||
return cursor.topology.selectServer(cursor.options, (err, server) => { | ||
if (err) { | ||
// Handle the error and add object to next method call | ||
if (cursor.disconnectHandler != null) { | ||
return cursor.disconnectHandler.addObjectAndMethod( | ||
'cursor', | ||
cursor, | ||
'next', | ||
[callback], | ||
callback | ||
); | ||
} | ||
return callback(err); | ||
} | ||
cursor.server = server; | ||
// Set as init | ||
cursor.cursorState.init = true; | ||
// error if collation not supported | ||
if (collationNotSupported(cursor.server, cursor.cmd)) { | ||
return callback(new MongoError(`server ${cursor.server.name} does not support collation`)); | ||
} | ||
try { | ||
cursor.query = cursor.server.wireProtocolHandler.command( | ||
cursor.bson, | ||
cursor.ns, | ||
cursor.cmd, | ||
cursor.cursorState, | ||
cursor.topology, | ||
cursor.options | ||
); | ||
if (cursor.query instanceof MongoError) { | ||
return callback(cursor.query); | ||
} | ||
// call `nextFunction` again now that we are initialized | ||
nextFunction(cursor, callback); | ||
} catch (err) { | ||
return callback(err); | ||
} | ||
}); | ||
} | ||
/** | ||
@@ -822,0 +830,0 @@ * Retrieve the next document from the cursor |
@@ -571,3 +571,3 @@ 'use strict'; | ||
// Move to the connected servers | ||
moveServerFrom(self.disconnectedProxies, self.connectedProxies, _self); | ||
moveServerFrom(self.connectingProxies, self.connectedProxies, _self); | ||
// Emit topology Change | ||
@@ -578,3 +578,3 @@ emitTopologyDescriptionChanged(self); | ||
}); | ||
} else if (event === 'connect' && self.authenticating) { | ||
} else { | ||
// Move from connectingProxies | ||
@@ -618,2 +618,5 @@ moveServerFrom(self.connectingProxies, self.disconnectedProxies, _self); | ||
_server.destroy(); | ||
removeProxyFrom(self.disconnectedProxies, _server); | ||
// Relay the server description change | ||
@@ -641,2 +644,3 @@ server.on('serverDescriptionChanged', function(event) { | ||
// Connect to proxy | ||
self.connectingProxies.push(server); | ||
server.connect(self.s.connectOptions); | ||
@@ -1287,23 +1291,22 @@ }, i); | ||
/** | ||
* Get server | ||
* Selects a server | ||
* | ||
* @method | ||
* @return {Server} | ||
* @param {function} selector Unused | ||
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it | ||
* @param {function} callback | ||
*/ | ||
Mongos.prototype.getServer = function() { | ||
var server = pickProxy(this); | ||
Mongos.prototype.selectServer = function(selector, options, callback) { | ||
if (typeof selector === 'function' && typeof callback === 'undefined') | ||
(callback = selector), (selector = undefined), (options = {}); | ||
if (typeof options === 'function') | ||
(callback = options), (options = selector), (selector = undefined); | ||
options = options || {}; | ||
const server = pickProxy(this); | ||
if (this.s.debug) this.emit('pickedServer', null, server); | ||
return server; | ||
callback(null, server); | ||
}; | ||
/** | ||
* Get a direct connection | ||
* @method | ||
* @return {Connection} | ||
*/ | ||
Mongos.prototype.getConnection = function() { | ||
var server = this.getServer(); | ||
if (server) return server.getConnection(); | ||
}; | ||
/** | ||
* All raw connections | ||
@@ -1310,0 +1313,0 @@ * @method |
@@ -1133,28 +1133,22 @@ 'use strict'; | ||
/** | ||
* Get server | ||
* Selects a server | ||
* | ||
* @method | ||
* @param {function} selector Unused | ||
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it | ||
* @return {Server} | ||
* @param {function} callback | ||
*/ | ||
ReplSet.prototype.getServer = function(options) { | ||
// Ensure we have no options | ||
ReplSet.prototype.selectServer = function(selector, options, callback) { | ||
if (typeof selector === 'function' && typeof callback === 'undefined') | ||
(callback = selector), (selector = undefined), (options = {}); | ||
if (typeof options === 'function') | ||
(callback = options), (options = selector), (selector = undefined); | ||
options = options || {}; | ||
// Pick the right server based on readPreference | ||
var server = this.s.replicaSetState.pickServer(options.readPreference); | ||
const server = this.s.replicaSetState.pickServer(options.readPreference); | ||
if (this.s.debug) this.emit('pickedServer', options.readPreference, server); | ||
return server; | ||
callback(null, server); | ||
}; | ||
/** | ||
* Get a direct connection | ||
* @method | ||
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it | ||
* @return {Connection} | ||
*/ | ||
ReplSet.prototype.getConnection = function(options) { | ||
var server = this.getServer(options); | ||
if (server) return server.getConnection(); | ||
}; | ||
/** | ||
* Get all connected servers | ||
@@ -1161,0 +1155,0 @@ * @method |
@@ -982,17 +982,12 @@ 'use strict'; | ||
/** | ||
* Get server | ||
* @method | ||
* Selects a server | ||
* @return {Server} | ||
*/ | ||
Server.prototype.getServer = function() { | ||
return this; | ||
}; | ||
Server.prototype.selectServer = function(selector, options, callback) { | ||
if (typeof selector === 'function' && typeof callback === 'undefined') | ||
(callback = selector), (selector = undefined), (options = {}); | ||
if (typeof options === 'function') | ||
(callback = options), (options = selector), (selector = undefined); | ||
/** | ||
* Get connection | ||
* @method | ||
* @return {Connection} | ||
*/ | ||
Server.prototype.getConnection = function() { | ||
return this.s.pool.get(); | ||
callback(null, this); | ||
}; | ||
@@ -1010,2 +1005,4 @@ | ||
Server.prototype.destroy = function(options) { | ||
if (this._destroyed) return; | ||
options = options || {}; | ||
@@ -1023,3 +1020,6 @@ var self = this; | ||
// No pool, return | ||
if (!self.s.pool) return; | ||
if (!self.s.pool) { | ||
this._destroyed = true; | ||
return; | ||
} | ||
@@ -1059,2 +1059,3 @@ // Emit close event | ||
this.s.pool.destroy(options.force); | ||
this._destroyed = true; | ||
}; | ||
@@ -1061,0 +1062,0 @@ |
{ | ||
"name": "mongodb-core", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "Core MongoDB driver functionality, no bells and whistles and meant for integration not end applications", | ||
@@ -23,3 +23,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"bson": "~1.0.4", | ||
"bson": "^1.1.0", | ||
"require_optional": "^1.0.1" | ||
@@ -26,0 +26,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
749893
15219
+ Addedbson@1.1.6(transitive)
- Removedbson@1.0.9(transitive)
Updatedbson@^1.1.0