🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

mongodb-memory-server-core

Package Overview
Dependencies
Maintainers
2
Versions
280
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-memory-server-core - npm Package Compare versions

Comparing version

to
9.0.0-beta.3

5

lib/util/getport/index.js

@@ -83,3 +83,6 @@ "use strict";

const server = http.createServer();
server.unref(); // dont keep this server from exiting the application
// some engines dont support ".unref"(net / tcp.unref), like "deno" in the past and now "bun"
if (typeof server.unref === 'function') {
server.unref(); // dont keep this server from exiting the application
}
server.on('error', (err) => {

@@ -86,0 +89,0 @@ if (err?.code !== 'EADDRINUSE') {

9

lib/util/MongoBinaryDownloadUrl.js

@@ -224,3 +224,6 @@ "use strict";

}
if (release >= 11 || ['unstable', 'testing'].includes(os.release)) {
// without any "release"(empty string), fallback to testing
// see https://tracker.debian.org/news/1433360/accepted-base-files-13-source-into-unstable/
const isTesting = ['unstable', 'testing', ''].includes(os.release);
if (isTesting || release >= 11) {
// Debian 11 is compatible with the binaries for debian 10

@@ -249,5 +252,5 @@ // but does not have binaries for before 5.0.8

}
if (release >= 10) {
if (isTesting || release >= 10) {
if (semver.lt(coercedVersion, '4.2.1') && !testVersionIsLatest(this.version)) {
throw new errors_1.KnownVersionIncompatibilityError(`Debian ${release}`, this.version, '>=4.2.1', 'Mongodb does not provide binaries for versions before 4.2.1 for Debian 10+ and also cannot be mapped to a previous Debian release');
throw new errors_1.KnownVersionIncompatibilityError(`Debian ${release || os.release || os.codename}`, this.version, '>=4.2.1', 'Mongodb does not provide binaries for versions before 4.2.1 for Debian 10+ and also cannot be mapped to a previous Debian release');
}

@@ -254,0 +257,0 @@ }

@@ -204,2 +204,8 @@ /// <reference types="node" />

isReplSet: boolean;
/**
* Extra promise to avoid multiple calls of `.stop` at the same time
*
* @see https://github.com/nodkz/mongodb-memory-server/issues/802
*/
stopPromise?: Promise<boolean>;
constructor(opts: Partial<MongodOpts>);

@@ -206,0 +212,0 @@ /**

@@ -175,54 +175,63 @@ "use strict";

}
if (!(0, utils_1.isNullOrUndefined)(this.mongodProcess)) {
// try to run "shutdown" before running "killProcess" (gracefull "SIGINT")
// using this, otherwise on windows nodejs will handle "SIGINT" & "SIGTERM" & "SIGKILL" the same (instant exit)
if (this.isReplSet) {
let con;
try {
this.debug('stop: trying shutdownServer');
const port = this.instanceOpts.port;
const ip = this.instanceOpts.ip;
(0, utils_1.assertion)(!(0, utils_1.isNullOrUndefined)(port), new Error('Cannot shutdown replset gracefully, no "port" is provided'));
(0, utils_1.assertion)(!(0, utils_1.isNullOrUndefined)(ip), new Error('Cannot shutdown replset gracefully, no "ip" is provided'));
con = await mongodb_1.MongoClient.connect((0, utils_1.uriTemplate)(ip, port, 'admin'), {
...this.extraConnectionOptions,
directConnection: true,
});
const admin = con.db('admin'); // just to ensure it is actually the "admin" database
// "timeoutSecs" is set to "1" otherwise it will take at least "10" seconds to stop (very long tests)
await admin.command({ shutdown: 1, force: true, timeoutSecs: 1 });
this.debug('stop: after admin shutdown command');
}
catch (err) {
// Quote from MongoDB Documentation (https://docs.mongodb.com/manual/reference/command/replSetStepDown/#client-connections):
// > Starting in MongoDB 4.2, replSetStepDown command no longer closes all client connections.
// > In MongoDB 4.0 and earlier, replSetStepDown command closes all client connections during the step down.
// so error "MongoNetworkError: connection 1 to 127.0.0.1:41485 closed" will get thrown below 4.2
if (!(err instanceof mongodb_1.MongoNetworkError &&
/^connection \d+ to [\d.]+:\d+ closed$/i.test(err.message))) {
console.warn(err);
if (!(0, utils_1.isNullOrUndefined)(this.stopPromise)) {
this.debug('stop: stopPromise is already set, using that');
return this.stopPromise;
}
// wrap the actual stop in a promise, so it can be awaited in multiple calls
// for example a instanceError while stop is already running would cause another stop
this.stopPromise = (async () => {
if (!(0, utils_1.isNullOrUndefined)(this.mongodProcess)) {
// try to run "shutdown" before running "killProcess" (gracefull "SIGINT")
// using this, otherwise on windows nodejs will handle "SIGINT" & "SIGTERM" & "SIGKILL" the same (instant exit)
if (this.isReplSet) {
let con;
try {
this.debug('stop: trying shutdownServer');
const port = this.instanceOpts.port;
const ip = this.instanceOpts.ip;
(0, utils_1.assertion)(!(0, utils_1.isNullOrUndefined)(port), new Error('Cannot shutdown replset gracefully, no "port" is provided'));
(0, utils_1.assertion)(!(0, utils_1.isNullOrUndefined)(ip), new Error('Cannot shutdown replset gracefully, no "ip" is provided'));
con = await mongodb_1.MongoClient.connect((0, utils_1.uriTemplate)(ip, port, 'admin'), {
...this.extraConnectionOptions,
directConnection: true,
});
const admin = con.db('admin'); // just to ensure it is actually the "admin" database
// "timeoutSecs" is set to "1" otherwise it will take at least "10" seconds to stop (very long tests)
await admin.command({ shutdown: 1, force: true, timeoutSecs: 1 });
this.debug('stop: after admin shutdown command');
}
}
finally {
if (!(0, utils_1.isNullOrUndefined)(con)) {
// even if it errors out, somehow the connection stays open
await con.close();
catch (err) {
// Quote from MongoDB Documentation (https://docs.mongodb.com/manual/reference/command/replSetStepDown/#client-connections):
// > Starting in MongoDB 4.2, replSetStepDown command no longer closes all client connections.
// > In MongoDB 4.0 and earlier, replSetStepDown command closes all client connections during the step down.
// so error "MongoNetworkError: connection 1 to 127.0.0.1:41485 closed" will get thrown below 4.2
if (!(err instanceof mongodb_1.MongoNetworkError &&
/^connection \d+ to [\d.]+:\d+ closed$/i.test(err.message))) {
console.warn(err);
}
}
finally {
if (!(0, utils_1.isNullOrUndefined)(con)) {
// even if it errors out, somehow the connection stays open
await con.close();
}
}
}
await (0, utils_1.killProcess)(this.mongodProcess, 'mongodProcess', this.instanceOpts.port);
this.mongodProcess = undefined; // reset reference to the childProcess for "mongod"
}
await (0, utils_1.killProcess)(this.mongodProcess, 'mongodProcess', this.instanceOpts.port);
this.mongodProcess = undefined; // reset reference to the childProcess for "mongod"
}
else {
this.debug('stop: mongodProcess: nothing to shutdown, skipping');
}
if (!(0, utils_1.isNullOrUndefined)(this.killerProcess)) {
await (0, utils_1.killProcess)(this.killerProcess, 'killerProcess', this.instanceOpts.port);
this.killerProcess = undefined; // reset reference to the childProcess for "mongo_killer"
}
else {
this.debug('stop: killerProcess: nothing to shutdown, skipping');
}
this.debug('stop: Instance Finished Shutdown');
return true;
else {
this.debug('stop: mongodProcess: nothing to shutdown, skipping');
}
if (!(0, utils_1.isNullOrUndefined)(this.killerProcess)) {
await (0, utils_1.killProcess)(this.killerProcess, 'killerProcess', this.instanceOpts.port);
this.killerProcess = undefined; // reset reference to the childProcess for "mongo_killer"
}
else {
this.debug('stop: killerProcess: nothing to shutdown, skipping');
}
this.debug('stop: Instance Finished Shutdown');
return true;
})().finally(() => (this.stopPromise = undefined));
return this.stopPromise;
}

@@ -229,0 +238,0 @@ /**

{
"name": "mongodb-memory-server-core",
"version": "9.0.0-beta.2",
"version": "9.0.0-beta.3",
"description": "MongoDB Server for testing (core package, without autodownload). The server will allow you to connect your favourite ODM or client library to the MongoDB Server and run parallel integration tests isolated from each other.",

@@ -34,10 +34,10 @@ "main": "lib/index",

"devDependencies": {
"@types/debug": "^4.1.8",
"@types/debug": "^4.1.9",
"@types/find-cache-dir": "^3.2.1",
"@types/follow-redirects": "^1.14.1",
"@types/semver": "^7.5.0",
"@types/tar-stream": "^2.2.2",
"@types/yauzl": "^2.10.0",
"@types/yazl": "^2.4.2",
"rimraf": "^5.0.1",
"@types/follow-redirects": "^1.14.2",
"@types/semver": "^7.5.3",
"@types/tar-stream": "^3.1.1",
"@types/yauzl": "^2.10.1",
"@types/yazl": "^2.4.3",
"rimraf": "^5.0.5",
"saslprep": "^1.0.3",

@@ -51,5 +51,5 @@ "yazl": "^2.5.1"

"find-cache-dir": "^3.3.2",
"follow-redirects": "^1.15.2",
"https-proxy-agent": "^7.0.1",
"mongodb": "^5.8.0",
"follow-redirects": "^1.15.3",
"https-proxy-agent": "^7.0.2",
"mongodb": "^5.9.0",
"new-find-package-json": "^2.0.0",

@@ -56,0 +56,0 @@ "semver": "^7.5.4",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet