Socket
Socket
Sign inDemoInstall

mongodb-core

Package Overview
Dependencies
Maintainers
3
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.2.0-beta2 to 3.2.0

lib/wireprotocol/constants.js

42

HISTORY.md

@@ -5,2 +5,44 @@ # Change Log

<a name="3.2.0"></a>
# [3.2.0](https://github.com/mongodb-js/mongodb-core/compare/v3.1.11...v3.2.0) (2019-03-21)
### Bug Fixes
* **command:** invert boolean expression for applying `$query` ([8513ad5](https://github.com/mongodb-js/mongodb-core/commit/8513ad5))
* **command:** only add `$query` to command in OP_QUERY ([3e57690](https://github.com/mongodb-js/mongodb-core/commit/3e57690))
* **cursor:** ensure that cursor id defaults to 0 ([e7e1775](https://github.com/mongodb-js/mongodb-core/commit/e7e1775))
* **get-more:** documents are already returned as raw in this case ([c81f609](https://github.com/mongodb-js/mongodb-core/commit/c81f609))
* **msg:** support raw cursor results using OP_MSG ([f91304b](https://github.com/mongodb-js/mongodb-core/commit/f91304b))
* **op-msg:** only include `$readPreference` if not primary ([0d10317](https://github.com/mongodb-js/mongodb-core/commit/0d10317))
* **scram:** allow errors to be passed through callbacks ([dccc2ba](https://github.com/mongodb-js/mongodb-core/commit/dccc2ba))
* **sessions:** enable sessions in OP_MSG ([d8bf209](https://github.com/mongodb-js/mongodb-core/commit/d8bf209))
* **topology:** correctly pick up command options for cursors ([259231e](https://github.com/mongodb-js/mongodb-core/commit/259231e))
* **topology:** ensure read preferences are translated on selection ([ebefb7b](https://github.com/mongodb-js/mongodb-core/commit/ebefb7b))
* **transactions:** only send recovery token on commitTransaction ([923a089](https://github.com/mongodb-js/mongodb-core/commit/923a089))
* **transactions:** special case non-deterministic wc errors in txns ([5a2ae77](https://github.com/mongodb-js/mongodb-core/commit/5a2ae77))
* **transactions:** write concern is always majority on txn retry ([7b240ea](https://github.com/mongodb-js/mongodb-core/commit/7b240ea))
* **with-transaction:** throw a useful error on invalid return type ([ae64bb4](https://github.com/mongodb-js/mongodb-core/commit/ae64bb4))
* make mongos write commands work the same as replset write commands ([31b984f](https://github.com/mongodb-js/mongodb-core/commit/31b984f))
### Features
* **auth:** add authentication to handshake process ([aacac68](https://github.com/mongodb-js/mongodb-core/commit/aacac68))
* **error:** all `hasErrorLabel` method to MongoError ([32a5e74](https://github.com/mongodb-js/mongodb-core/commit/32a5e74))
* **OP_MSG:** add in parsing of OP_MSG ([c310a83](https://github.com/mongodb-js/mongodb-core/commit/c310a83))
* **OP_MSG:** adding class for translating OP_MSG from binary ([11e4132](https://github.com/mongodb-js/mongodb-core/commit/11e4132))
* **OP_MSG:** adding OP_MSG implementation ([c5adfa3](https://github.com/mongodb-js/mongodb-core/commit/c5adfa3))
* **op-msg:** add support for `OP_MSG` to command monitoring ([9124b67](https://github.com/mongodb-js/mongodb-core/commit/9124b67))
* **sdam:** backport unified SDAM changes from `next` to `master` ([83d744c](https://github.com/mongodb-js/mongodb-core/commit/83d744c))
* **topology-description:** always calculate commonWireVersion ([5c630ab](https://github.com/mongodb-js/mongodb-core/commit/5c630ab))
* **transactions:** tack recovery token for sharded transactions ([e12ae70](https://github.com/mongodb-js/mongodb-core/commit/e12ae70))
* add ability to pin server to transaction state machine ([da13e55](https://github.com/mongodb-js/mongodb-core/commit/da13e55))
* update proxy selection to consider pinned server on session ([189e428](https://github.com/mongodb-js/mongodb-core/commit/189e428))
* **txns:** support mongos pinning in unified topology ([78dab5d](https://github.com/mongodb-js/mongodb-core/commit/78dab5d))
* **with-transaction:** provide helper for convenient txn api ([478d1e7](https://github.com/mongodb-js/mongodb-core/commit/478d1e7))
* **withTransaction:** retry transaction commit on wtimeout ([2bc705c](https://github.com/mongodb-js/mongodb-core/commit/2bc705c))
<a name="3.1.11"></a>

@@ -7,0 +49,0 @@ ## [3.1.11](https://github.com/mongodb-js/mongodb-core/compare/v3.1.10...v3.1.11) (2019-01-16)

57

lib/connection/connect.js

@@ -9,2 +9,7 @@ 'use strict';

const defaultAuthProviders = require('../auth/defaultAuthProviders').defaultAuthProviders;
const WIRE_CONSTANTS = require('../wireprotocol/constants');
const MAX_SUPPORTED_WIRE_VERSION = WIRE_CONSTANTS.MAX_SUPPORTED_WIRE_VERSION;
const MAX_SUPPORTED_SERVER_VERSION = WIRE_CONSTANTS.MAX_SUPPORTED_SERVER_VERSION;
const MIN_SUPPORTED_WIRE_VERSION = WIRE_CONSTANTS.MIN_SUPPORTED_WIRE_VERSION;
const MIN_SUPPORTED_SERVER_VERSION = WIRE_CONSTANTS.MIN_SUPPORTED_SERVER_VERSION;
let AUTH_PROVIDERS;

@@ -48,6 +53,2 @@

function isSupportedServer(ismaster) {
return ismaster && typeof ismaster.maxWireVersion === 'number' && ismaster.maxWireVersion >= 2;
}
function getSaslSupportedMechs(options) {

@@ -76,2 +77,30 @@ if (!(options && options.credentials)) {

function checkSupportedServer(ismaster, options) {
const serverVersionHighEnough =
ismaster &&
typeof ismaster.maxWireVersion === 'number' &&
ismaster.maxWireVersion >= MIN_SUPPORTED_WIRE_VERSION;
const serverVersionLowEnough =
ismaster &&
typeof ismaster.minWireVersion === 'number' &&
ismaster.minWireVersion <= MAX_SUPPORTED_WIRE_VERSION;
if (serverVersionHighEnough) {
if (serverVersionLowEnough) {
return null;
}
const message = `Server at ${options.host}:${options.port} reports minimum wire version ${
ismaster.minWireVersion
}, but this version of the Node.js Driver requires at most ${MAX_SUPPORTED_WIRE_VERSION} (MongoDB ${MAX_SUPPORTED_SERVER_VERSION})`;
return new MongoError(message);
}
const message = `Server at ${options.host}:${
options.port
} reports maximum wire version ${ismaster.maxWireVersion ||
0}, but this version of the Node.js Driver requires at least ${MIN_SUPPORTED_WIRE_VERSION} (MongoDB ${MIN_SUPPORTED_SERVER_VERSION})`;
return new MongoError(message);
}
function performInitialHandshake(conn, options, callback) {

@@ -104,19 +133,5 @@ let compressors = [];

if (!isSupportedServer(ismaster)) {
const latestSupportedVersion = '2.6';
const latestSupportedMaxWireVersion = 2;
const message =
'Server at ' +
options.host +
':' +
options.port +
' reports wire version ' +
(ismaster.maxWireVersion || 0) +
', but this version of the Node.js Driver requires at least ' +
latestSupportedMaxWireVersion +
' (MongoDB' +
latestSupportedVersion +
').';
callback(new MongoError(message), null);
const supportedServerErr = checkSupportedServer(ismaster, options);
if (supportedServerErr) {
callback(supportedServerErr, null);
return;

@@ -123,0 +138,0 @@ }

@@ -196,3 +196,10 @@ 'use strict';

*/
destroy() {
destroy(options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}
options = Object.assign({ force: false }, options);
if (connectionAccounting) {

@@ -202,12 +209,18 @@ deleteConnection(this.id);

if (this.socket) {
// Catch posssible exception thrown by node 0.10.x
try {
this.socket.end();
} catch (err) {} // eslint-disable-line
if (this.socket == null) {
this.destroyed = true;
return;
}
if (options.force) {
this.socket.destroy();
this.destroyed = true;
if (typeof callback === 'function') callback(null, null);
return;
}
this.destroyed = true;
this.socket.end(err => {
this.destroyed = true;
if (typeof callback === 'function') callback(err, null);
});
}

@@ -214,0 +227,0 @@

@@ -638,20 +638,35 @@ 'use strict';

// Destroy the connections
function destroy(self, connections) {
function destroy(self, connections, options, callback) {
let connectionCount = connections.length;
function connectionDestroyed() {
connectionCount--;
if (connectionCount > 0) {
return;
}
// Zero out all connections
self.inUseConnections = [];
self.availableConnections = [];
self.connectingConnections = 0;
// Set state to destroyed
stateTransition(self, DESTROYED);
if (typeof callback === 'function') {
callback(null, null);
}
}
if (connectionCount === 0) {
connectionDestroyed();
return;
}
// Destroy all connections
connections.forEach(function(c) {
// Remove all listeners
connections.forEach(conn => {
for (var i = 0; i < events.length; i++) {
c.removeAllListeners(events[i]);
conn.removeAllListeners(events[i]);
}
// Destroy connection
c.destroy();
conn.destroy(options, connectionDestroyed);
});
// Zero out all connections
self.inUseConnections = [];
self.availableConnections = [];
self.connectingConnections = 0;
// Set state to destroyed
stateTransition(self, DESTROYED);
}

@@ -663,6 +678,10 @@

*/
Pool.prototype.destroy = function(force) {
Pool.prototype.destroy = function(force, callback) {
var self = this;
// Do not try again if the pool is already dead
if (this.state === DESTROYED || self.state === DESTROYING) return;
if (this.state === DESTROYED || self.state === DESTROYING) {
if (typeof callback === 'function') callback(null, null);
return;
}
// Set state to destroyed

@@ -686,3 +705,3 @@ stateTransition(this, DESTROYING);

// Destroy the topology
return destroy(self, connections);
return destroy(self, connections, { force: true }, callback);
}

@@ -718,3 +737,3 @@

destroy(self, connections);
destroy(self, connections, { force: false }, callback);
// } else if (self.queue.length > 0 && !this.reconnectId) {

@@ -721,0 +740,0 @@ } else {

@@ -5,7 +5,9 @@ 'use strict';

const ReadPreference = require('../topologies/read_preference');
const WIRE_CONSTANTS = require('../wireprotocol/constants');
// contstants related to compatability checks
const MIN_SUPPORTED_SERVER_VERSION = '2.6';
const MIN_SUPPORTED_WIRE_VERSION = 2;
const MAX_SUPPORTED_WIRE_VERSION = 5;
const MIN_SUPPORTED_SERVER_VERSION = WIRE_CONSTANTS.MIN_SUPPORTED_SERVER_VERSION;
const MAX_SUPPORTED_SERVER_VERSION = WIRE_CONSTANTS.MAX_SUPPORTED_SERVER_VERSION;
const MIN_SUPPORTED_WIRE_VERSION = WIRE_CONSTANTS.MIN_SUPPORTED_WIRE_VERSION;
const MAX_SUPPORTED_WIRE_VERSION = WIRE_CONSTANTS.MAX_SUPPORTED_WIRE_VERSION;

@@ -70,3 +72,3 @@ // An enumeration of topology types we know about

serverDescription.minWireVersion
}, but this version of the driver only supports up to ${MAX_SUPPORTED_WIRE_VERSION}.`;
}, but this version of the driver only supports up to ${MAX_SUPPORTED_WIRE_VERSION} (MongoDB ${MAX_SUPPORTED_SERVER_VERSION})`;
}

@@ -73,0 +75,0 @@

@@ -476,3 +476,7 @@ 'use strict';

if (commandName === 'commitTransaction' && session.transaction.recoveryToken) {
if (
commandName === 'commitTransaction' &&
session.transaction.recoveryToken &&
supportsRecoveryToken(session)
) {
command.recoveryToken = session.transaction.recoveryToken;

@@ -503,2 +507,7 @@ }

function supportsRecoveryToken(session) {
const topology = session.topology;
return !!topology.s.options.useRecoveryToken;
}
/**

@@ -505,0 +514,0 @@ * Reflects the existence of a session on the server. Can be reused by the session pool.

@@ -257,6 +257,6 @@ 'use strict';

const SERVER_EVENTS = ['serverDescriptionChanged', 'error', 'close', 'timeout', 'parseError'];
function destroyServer(server, options) {
function destroyServer(server, options, callback) {
options = options || {};
SERVER_EVENTS.forEach(event => server.removeAllListeners(event));
server.destroy(options);
server.destroy(options, callback);
}

@@ -812,28 +812,39 @@

*/
Mongos.prototype.destroy = function(options) {
var self = this;
// Transition state
stateTransition(this, DESTROYED);
// Get all proxies
var proxies = this.connectedProxies.concat(this.connectingProxies);
// Clear out any monitoring process
if (this.haTimeoutId) clearTimeout(this.haTimeoutId);
Mongos.prototype.destroy = function(options, callback) {
if (this.haTimeoutId) {
clearTimeout(this.haTimeoutId);
}
const proxies = this.connectedProxies.concat(this.connectingProxies);
let serverCount = proxies.length;
const serverDestroyed = () => {
serverCount--;
if (serverCount > 0) {
return;
}
emitTopologyDescriptionChanged(this);
emitSDAMEvent(this, 'topologyClosed', { topologyId: this.id });
stateTransition(this, DESTROYED);
if (typeof callback === 'function') {
callback(null, null);
}
};
if (serverCount === 0) {
serverDestroyed();
return;
}
// Destroy all connecting servers
proxies.forEach(function(server) {
proxies.forEach(server => {
// Emit the sdam event
self.emit('serverClosed', {
topologyId: self.id,
this.emit('serverClosed', {
topologyId: this.id,
address: server.name
});
destroyServer(server, options);
// Move to list of disconnectedProxies
moveServerFrom(self.connectedProxies, self.disconnectedProxies, server);
destroyServer(server, options, serverDestroyed);
moveServerFrom(this.connectedProxies, this.disconnectedProxies, server);
});
// Emit the final topology change
emitTopologyDescriptionChanged(self);
// Emit toplogy closing event
emitSDAMEvent(this, 'topologyClosed', { topologyId: this.id });
};

@@ -840,0 +851,0 @@

@@ -119,27 +119,39 @@ 'use strict';

ReplSetState.prototype.destroy = function(options) {
// Destroy all sockets
if (this.primary) this.primary.destroy(options);
this.secondaries.forEach(function(x) {
x.destroy(options);
});
this.arbiters.forEach(function(x) {
x.destroy(options);
});
this.passives.forEach(function(x) {
x.destroy(options);
});
this.ghosts.forEach(function(x) {
x.destroy(options);
});
// Clear out the complete state
this.secondaries = [];
this.arbiters = [];
this.passives = [];
this.ghosts = [];
this.unknownServers = [];
this.set = {};
this.primary = null;
// Emit the topology changed
emitTopologyDescriptionChanged(this);
ReplSetState.prototype.destroy = function(options, callback) {
const serversToDestroy = this.secondaries
.concat(this.arbiters)
.concat(this.passives)
.concat(this.ghosts);
if (this.primary) serversToDestroy.push(this.primary);
let serverCount = serversToDestroy.length;
const serverDestroyed = () => {
serverCount--;
if (serverCount > 0) {
return;
}
// Clear out the complete state
this.secondaries = [];
this.arbiters = [];
this.passives = [];
this.ghosts = [];
this.unknownServers = [];
this.set = {};
this.primary = null;
// Emit the topology changed
emitTopologyDescriptionChanged(this);
if (typeof callback === 'function') {
callback(null, null);
}
};
if (serverCount === 0) {
serverDestroyed();
return;
}
serversToDestroy.forEach(server => server.destroy(options, serverDestroyed));
};

@@ -146,0 +158,0 @@

@@ -951,16 +951,26 @@ 'use strict';

*/
ReplSet.prototype.destroy = function(options) {
ReplSet.prototype.destroy = function(options, callback) {
options = options || {};
// Transition state
stateTransition(this, DESTROYED);
let destroyCount = this.s.connectingServers.length + 1; // +1 for the callback from `replicaSetState.destroy`
const serverDestroyed = () => {
destroyCount--;
if (destroyCount > 0) {
return;
}
// Emit toplogy closing event
emitSDAMEvent(this, 'topologyClosed', { topologyId: this.id });
// Transition state
stateTransition(this, DESTROYED);
if (typeof callback === 'function') {
callback(null, null);
}
};
// Clear out any monitoring process
if (this.haTimeoutId) clearTimeout(this.haTimeoutId);
// Destroy the replicaset
this.s.replicaSetState.destroy(options);
// Destroy all connecting servers
this.s.connectingServers.forEach(function(x) {
x.destroy(options);
});
// Clear out all monitoring

@@ -974,4 +984,14 @@ for (var i = 0; i < this.intervalIds.length; i++) {

// Emit toplogy closing event
emitSDAMEvent(this, 'topologyClosed', { topologyId: this.id });
if (destroyCount === 0) {
serverDestroyed();
return;
}
// Destroy the replicaset
this.s.replicaSetState.destroy(options, serverDestroyed);
// Destroy all connecting servers
this.s.connectingServers.forEach(function(x) {
x.destroy(options, serverDestroyed);
});
};

@@ -978,0 +998,0 @@

@@ -805,4 +805,7 @@ 'use strict';

*/
Server.prototype.destroy = function(options) {
if (this._destroyed) return;
Server.prototype.destroy = function(options, callback) {
if (this._destroyed) {
if (typeof callback === 'function') callback(null, null);
return;
}

@@ -823,2 +826,3 @@ options = options || {};

this._destroyed = true;
if (typeof callback === 'function') callback(null, null);
return;

@@ -859,3 +863,3 @@ }

// Destroy the pool
this.s.pool.destroy(options.force);
this.s.pool.destroy(options.force, callback);
this._destroyed = true;

@@ -862,0 +866,0 @@ };

{
"name": "mongodb-core",
"version": "3.2.0-beta2",
"version": "3.2.0",
"description": "Core MongoDB driver functionality, no bells and whistles and meant for integration not end applications",

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

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