This commit is contained in:
Jonasz Bigda
2023-03-25 21:51:42 +01:00
parent 0db1d5117e
commit b332e9ceb0
1044 changed files with 37502 additions and 63938 deletions

View File

@@ -41,6 +41,7 @@ const VALID_POOL_OPTIONS = new Set([
'ssl',
'bson',
'connectionType',
'serverApi',
'monitorCommands',
'socketTimeout',
'credentials',
@@ -95,7 +96,7 @@ const VALID_POOL_OPTIONS = new Set([
function resolveOptions(options, defaults) {
const newOptions = Array.from(VALID_POOL_OPTIONS).reduce((obj, key) => {
if (options.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(options, key)) {
obj[key] = options[key];
}
@@ -157,12 +158,13 @@ class ConnectionPool extends EventEmitter {
waitQueueTimeoutMS:
typeof options.waitQueueTimeoutMS === 'number' ? options.waitQueueTimeoutMS : 0,
autoEncrypter: options.autoEncrypter,
metadata: options.metadata
metadata: options.metadata,
useUnifiedTopology: options.useUnifiedTopology
});
if (options.minSize > options.maxSize) {
throw new TypeError(
'Connection pool minimum size must not be greater than maxiumum pool size'
'Connection pool minimum size must not be greater than maximum pool size'
);
}
@@ -218,7 +220,6 @@ class ConnectionPool extends EventEmitter {
return;
}
// add this request to the wait queue
const waitQueueMember = { callback };
const pool = this;
@@ -233,11 +234,8 @@ class ConnectionPool extends EventEmitter {
}, waitQueueTimeoutMS);
}
// place the member at the end of the wait queue
this[kWaitQueue].push(waitQueueMember);
// process the wait queue
processWaitQueue(this);
process.nextTick(() => processWaitQueue(this));
}
/**
@@ -250,10 +248,8 @@ class ConnectionPool extends EventEmitter {
const stale = connectionIsStale(this, connection);
const willDestroy = !!(poolClosed || stale || connection.closed);
// Properly adjust state of connection
if (!willDestroy) {
connection.markAvailable();
this[kConnections].push(connection);
}
@@ -264,7 +260,7 @@ class ConnectionPool extends EventEmitter {
destroyConnection(this, connection, reason);
}
processWaitQueue(this);
process.nextTick(() => processWaitQueue(this));
}
/**
@@ -434,7 +430,7 @@ function createConnection(pool, callback) {
// otherwise add it to the pool for later acquisition, and try to process the wait queue
pool[kConnections].push(connection);
processWaitQueue(pool);
process.nextTick(() => processWaitQueue(pool));
});
}
@@ -483,7 +479,7 @@ function processWaitQueue(pool) {
if (pool.waitQueueSize && (maxPoolSize <= 0 || pool.totalConnectionCount < maxPoolSize)) {
createConnection(pool, (err, connection) => {
const waitQueueMember = pool[kWaitQueue].shift();
if (waitQueueMember == null) {
if (waitQueueMember == null || waitQueueMember[kCancelled]) {
if (err == null) {
pool[kConnections].push(connection);
}
@@ -491,10 +487,6 @@ function processWaitQueue(pool) {
return;
}
if (waitQueueMember[kCancelled]) {
return;
}
if (err) {
pool.emit('connectionCheckOutFailed', new ConnectionCheckOutFailedEvent(pool, err));
} else {