Socket
Socket
Sign inDemoInstall

mongodb-core

Package Overview
Dependencies
Maintainers
2
Versions
177
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-core - npm Package Compare versions

Comparing version 3.0.0-rc0 to 3.0.0

21

HISTORY.md

@@ -0,1 +1,22 @@

<a name="3.0.0"></a>
# [3.0.0](https://github.com/christkv/mongodb-core/compare/v3.0.0-rc0...v3.0.0) (2017-12-23)
### Bug Fixes
* **connection:** ensure connection cleanup before fallback retry ([de62615](https://github.com/christkv/mongodb-core/commit/de62615))
* **mock-server:** expose potential errors in message handlers ([65dcca4](https://github.com/christkv/mongodb-core/commit/65dcca4))
* **mongos:** remove listener on destroy event ([243e942](https://github.com/christkv/mongodb-core/commit/243e942)), closes [#257](https://github.com/christkv/mongodb-core/issues/257)
* **sdam:** more explicit wire protocol error message ([6d6d19a](https://github.com/christkv/mongodb-core/commit/6d6d19a))
* **secondaries:** fixes connection with secondary readPreference ([#258](https://github.com/christkv/mongodb-core/issues/258)) ([0060ad7](https://github.com/christkv/mongodb-core/commit/0060ad7))
* **sessions:** ensure that we ignore session details from arbiters ([de0105c](https://github.com/christkv/mongodb-core/commit/de0105c))
* **sharded-tests:** add `shardsvr` cmdline opt, wait for async fns ([867b080](https://github.com/christkv/mongodb-core/commit/867b080))
### Features
* **connection:** attempt both ipv6 and ipv4 when no family entered ([#260](https://github.com/christkv/mongodb-core/issues/260)) ([107bae5](https://github.com/christkv/mongodb-core/commit/107bae5))
<a name="3.0.0-rc0"></a>

@@ -2,0 +23,0 @@ # 3.0.0-rc0 (2017-12-05)

188

lib/connection/connection.js

@@ -531,20 +531,55 @@ 'use strict';

/**
* Connect
* @method
*/
Connection.prototype.connect = function(_options) {
var self = this;
_options = _options || {};
// Set the connections
if (connectionAccounting) addConnection(this.id, this);
// Check if we are overriding the promoteLongs
if (typeof _options.promoteLongs === 'boolean') {
self.responseOptions.promoteLongs = _options.promoteLongs;
self.responseOptions.promoteValues = _options.promoteValues;
self.responseOptions.promoteBuffers = _options.promoteBuffers;
function makeSSLConnection(self, _options) {
let sslOptions = {
socket: self.connection,
rejectUnauthorized: self.rejectUnauthorized
};
// Merge in options
merge(sslOptions, this.options);
merge(sslOptions, _options);
// Set options for ssl
if (self.ca) sslOptions.ca = self.ca;
if (self.crl) sslOptions.crl = self.crl;
if (self.cert) sslOptions.cert = self.cert;
if (self.key) sslOptions.key = self.key;
if (self.passphrase) sslOptions.passphrase = self.passphrase;
// Override checkServerIdentity behavior
if (self.checkServerIdentity === false) {
// Skip the identiy check by retuning undefined as per node documents
// https://nodejs.org/api/tls.html#tls_tls_connect_options_callback
sslOptions.checkServerIdentity = function() {
return undefined;
};
} else if (typeof self.checkServerIdentity === 'function') {
sslOptions.checkServerIdentity = self.checkServerIdentity;
}
// Set default sni servername to be the same as host
if (sslOptions.servername == null) {
sslOptions.servername = self.host;
}
// Attempt SSL connection
const connection = tls.connect(self.port, self.host, sslOptions, function() {
// Error on auth or skip
if (connection.authorizationError && self.rejectUnauthorized) {
return self.emit('error', connection.authorizationError, self, { ssl: true });
}
// Set socket timeout instead of connection timeout
connection.setTimeout(self.socketTimeout);
// We are done emit connect
self.emit('connect', self);
});
connection.setTimeout(self.connectionTimeout);
return connection;
}
function makeUnsecureConnection(self, family) {
// Create new connection instance
var connection_options;
let connection_options;
if (self.domainSocket) {

@@ -554,74 +589,77 @@ connection_options = { path: self.host };

connection_options = { port: self.port, host: self.host };
if (self.family !== void 0) {
connection_options.family = self.family;
}
connection_options.family = family;
}
self.connection = net.createConnection(connection_options);
const connection = net.createConnection(connection_options);
// Set the options for the connection
self.connection.setKeepAlive(self.keepAlive, self.keepAliveInitialDelay);
self.connection.setTimeout(self.connectionTimeout);
self.connection.setNoDelay(self.noDelay);
connection.setKeepAlive(self.keepAlive, self.keepAliveInitialDelay);
connection.setTimeout(self.connectionTimeout);
connection.setNoDelay(self.noDelay);
// If we have ssl enabled
if (self.ssl) {
var sslOptions = {
socket: self.connection,
rejectUnauthorized: self.rejectUnauthorized
};
connection.once('connect', function() {
// Set socket timeout instead of connection timeout
connection.setTimeout(self.socketTimeout);
// Emit connect event
self.emit('connect', self);
});
// Merge in options
merge(sslOptions, this.options);
merge(sslOptions, _options);
return connection;
}
// Set options for ssl
if (self.ca) sslOptions.ca = self.ca;
if (self.crl) sslOptions.crl = self.crl;
if (self.cert) sslOptions.cert = self.cert;
if (self.key) sslOptions.key = self.key;
if (self.passphrase) sslOptions.passphrase = self.passphrase;
function doConnect(self, family, _options, _errorHandler) {
self.connection = self.ssl
? makeSSLConnection(self, _options)
: makeUnsecureConnection(self, family);
// Override checkServerIdentity behavior
if (self.checkServerIdentity === false) {
// Skip the identiy check by retuning undefined as per node documents
// https://nodejs.org/api/tls.html#tls_tls_connect_options_callback
sslOptions.checkServerIdentity = function() {
return undefined;
};
} else if (typeof self.checkServerIdentity === 'function') {
sslOptions.checkServerIdentity = self.checkServerIdentity;
}
// Add handlers for events
self.connection.once('error', _errorHandler);
self.connection.once('timeout', timeoutHandler(self));
self.connection.once('close', closeHandler(self));
self.connection.on('data', dataHandler(self));
}
// Set default sni servername to be the same as host
if (sslOptions.servername == null) {
sslOptions.servername = self.host;
}
/**
* Connect
* @method
*/
Connection.prototype.connect = function(_options) {
_options = _options || {};
// Set the connections
if (connectionAccounting) addConnection(this.id, this);
// Check if we are overriding the promoteLongs
if (typeof _options.promoteLongs === 'boolean') {
this.responseOptions.promoteLongs = _options.promoteLongs;
this.responseOptions.promoteValues = _options.promoteValues;
this.responseOptions.promoteBuffers = _options.promoteBuffers;
}
// Attempt SSL connection
self.connection = tls.connect(self.port, self.host, sslOptions, function() {
// Error on auth or skip
if (self.connection.authorizationError && self.rejectUnauthorized) {
return self.emit('error', self.connection.authorizationError, self, { ssl: true });
}
const _errorHandler = errorHandler(this);
// Set socket timeout instead of connection timeout
self.connection.setTimeout(self.socketTimeout);
// We are done emit connect
self.emit('connect', self);
});
self.connection.setTimeout(self.connectionTimeout);
} else {
self.connection.once('connect', function() {
// Set socket timeout instead of connection timeout
self.connection.setTimeout(self.socketTimeout);
// Emit connect event
self.emit('connect', self);
});
if (this.family !== void 0) {
return doConnect(this, this.family, _options, _errorHandler);
}
// Add handlers for events
self.connection.once('error', errorHandler(self));
self.connection.once('timeout', timeoutHandler(self));
self.connection.once('close', closeHandler(self));
self.connection.on('data', dataHandler(self));
return doConnect(this, 6, _options, err => {
if (this.logger.isDebug()) {
this.logger.debug(
f(
'connection %s for [%s:%s] errored out with [%s]',
this.id,
this.host,
this.port,
JSON.stringify(err)
)
);
}
// clean up existing event handlers
this.connection.removeAllListeners('error');
this.connection.removeAllListeners('timeout');
this.connection.removeAllListeners('close');
this.connection.removeAllListeners('data');
this.connection = undefined;
return doConnect(this, 4, _options, _errorHandler);
});
};

@@ -628,0 +666,0 @@

@@ -12,3 +12,2 @@ 'use strict';

CommandResult = require('./command_result'),
assign = require('../utils').assign,
MESSAGE_HEADER_SIZE = require('../wireprotocol/shared').MESSAGE_HEADER_SIZE,

@@ -84,3 +83,3 @@ opcodes = require('../wireprotocol/shared').opcodes,

// Add the options
this.options = assign(
this.options = Object.assign(
{

@@ -87,0 +86,0 @@ // Host and port settings

@@ -302,6 +302,11 @@ 'use strict';

const serverDescriptionChangedCallback = event => {
self.emit('serverDescriptionChanged', event);
};
servers.forEach(function(server) {
server.on('serverDescriptionChanged', function(event) {
self.emit('serverDescriptionChanged', event);
});
server.on('serverDescriptionChanged', serverDescriptionChangedCallback);
server.on('destroy', () =>
server.removeListener('serverDescriptionChanged', serverDescriptionChangedCallback)
);
});

@@ -855,3 +860,2 @@

});
// Emit the final topology change

@@ -858,0 +862,0 @@ emitTopologyDescriptionChanged(self);

@@ -203,2 +203,4 @@ 'use strict';

const isArbiter = ismaster => ismaster.arbiterOnly && ismaster.setName;
ReplSetState.prototype.update = function(server) {

@@ -270,3 +272,3 @@ var self = this;

// Update logicalSessionTimeoutMinutes
if (ismaster.logicalSessionTimeoutMinutes !== undefined) {
if (ismaster.logicalSessionTimeoutMinutes !== undefined && !isArbiter(ismaster)) {
if (

@@ -602,4 +604,3 @@ self.logicalSessionTimeoutMinutes === undefined ||

if (
ismaster.arbiterOnly &&
ismaster.setName &&
isArbiter(ismaster) &&
!inList(ismaster, server, this.arbiters) &&

@@ -606,0 +607,0 @@ this.setName &&

@@ -776,2 +776,18 @@ 'use strict';

function shouldTriggerConnect(self) {
const isConnecting = self.state === CONNECTING;
const hasPrimary = self.s.replicaSetState.hasPrimary();
const hasSecondary = self.s.replicaSetState.hasSecondary();
const secondaryOnlyConnectionAllowed = self.s.options.secondaryOnlyConnectionAllowed;
const readPreferenceSecondary =
self.s.connectOptions.readPreference &&
self.s.connectOptions.readPreference.equals(ReadPreference.secondary);
return (
(isConnecting &&
((readPreferenceSecondary && hasSecondary) || (!readPreferenceSecondary && hasPrimary))) ||
(hasSecondary && secondaryOnlyConnectionAllowed)
);
}
function handleInitialConnectEvent(self, event) {

@@ -839,6 +855,3 @@ return function() {

// Do we have a primary or primaryAndSecondary
if (
(self.state === CONNECTING && self.s.replicaSetState.hasPrimary()) ||
(self.s.replicaSetState.hasSecondary() && self.s.options.secondaryOnlyConnectionAllowed)
) {
if (shouldTriggerConnect(self)) {
// We are connected

@@ -845,0 +858,0 @@ self.state = CONNECTED;

@@ -18,3 +18,2 @@ 'use strict';

sdam = require('./shared'),
assign = require('../utils').assign,
createClientInfo = require('./shared').createClientInfo,

@@ -368,3 +367,14 @@ createCompressionInfo = require('./shared').createCompressionInfo,

self.destroy();
return self.emit('error', new MongoError('unsupported server version'), self);
const latestSupportedVersion = '2.6';
const message =
'Server at ' +
self.s.options.host +
':' +
self.s.options.port +
' reports wire version ' +
(result.result.maxWireVersion || 0) +
', but this version of Node.js Driver requires at least 2 (MongoDB' +
latestSupportedVersion +
').';
return self.emit('error', new MongoError(message), self);
}

@@ -539,3 +549,3 @@

// Create a pool
self.s.pool = new Pool(this, assign(self.s.options, options, { bson: this.s.bson }));
self.s.pool = new Pool(this, Object.assign(self.s.options, options, { bson: this.s.bson }));

@@ -663,3 +673,3 @@ // Set up listeners

// Clone the options
options = assign({}, options, { wireProtocolCommand: false });
options = Object.assign({}, options, { wireProtocolCommand: false });

@@ -666,0 +676,0 @@ // Debug log

@@ -5,33 +5,2 @@ 'use strict';

/**
* Copy the values of all enumerable own properties from one or more
* source objects to a target object. It will return the target object.
*/
const assign = Object.assign
? Object.assign
: function assign(target) {
if (target === undefined || target === null) {
throw new TypeError('Cannot convert first argument to object');
}
var to = Object(target);
for (var i = 1; i < arguments.length; i++) {
var nextSource = arguments[i];
if (nextSource === undefined || nextSource === null) {
continue;
}
var keysArray = Object.keys(Object(nextSource));
for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
var nextKey = keysArray[nextIndex];
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
if (desc !== undefined && desc.enumerable) {
to[nextKey] = nextSource[nextKey];
}
}
}
return to;
};
const uuidV4 = () => {

@@ -45,4 +14,3 @@ const result = crypto.randomBytes(16);

module.exports = {
assign: assign,
uuidV4: uuidV4
};
{
"name": "mongodb-core",
"version": "3.0.0-rc0",
"version": "3.0.0",
"description": "Core MongoDB driver functionality, no bells and whistles and meant for integration not end applications",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc