node_modules: update (#362)

Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com>
This commit is contained in:
Dawid Dziurlaanddawidd6 authored and GitHub committed 2026-11-11 07:38:40 +01:00
1 parent 4a48500d96
commit aefdaa6a6c
49 files changed
+1316 -295

No files matched your search

+10 -3
View File
@@ -76,6 +76,7 @@ export interface SMTPPoolRateLimit {
* @param options SMTP Connection options
*/
declare class SMTPPool extends EventEmitter {
readonly supportsAbortSignal = true;
options: SMTPPoolResolvedOptions;
logger: shared.Logger;
name: string;
@@ -102,10 +103,16 @@ declare class SMTPPool extends EventEmitter {
*/
send(mail: MailMessage<SMTPPoolSentMessageInfo>, callback: SMTPPoolSendCallback): boolean;
/**
* Closes all connections in the pool. If there is a message being sent, the connection
* is closed later
* Closes the pool. Idle connections are closed at once and a connection in the middle of a
* delivery finishes it first, unless `force` is set: then it is closed too and its message
* fails. `force` is for a caller that has given up on a delivery, such as one a server is
* stalling by trickling its replies, which no socket timeout notices.
*
* @param options.force - Also close connections that are delivering a message
*/
close(): void;
close(options?: {
force?: boolean;
}): void;
/**
* Returns true if there are free slots in the queue
*/
+70 -12
View File
@@ -56,6 +56,7 @@ const REQUEUE_MAX_DELAY = 2000;
class SMTPPool extends node_events_1.EventEmitter {
constructor(options) {
super();
this.supportsAbortSignal = true;
options = options || {};
if (typeof options === 'string') {
options = {
@@ -134,20 +135,33 @@ class SMTPPool extends node_events_1.EventEmitter {
return false;
}
// counted until the callback runs, whichever path runs it: delivered, failed, requeued
// until it gives up, or drained by close()
// until it gives up, aborted, or drained by close()
let counted = true;
let detachSignal;
this._pending++;
this._queue.push({
const entry = {
mail,
requeueAttempts: 0,
callback: (err, info) => {
if (counted) {
counted = false;
this._pending--;
if (!counted) {
return;
}
counted = false;
this._pending--;
detachSignal?.();
entry.resource = undefined;
callback(err, info);
}
});
};
this._queue.push(entry);
const signal = mail.data.signal;
if (signal) {
// one listener for the original entry, retained across connection-close retries
detachSignal = this._watchAbortSignal(entry, signal, () => counted);
if (signal.aborted) {
return true;
}
}
if (this.idling && this._queue.length >= this.options.maxConnections) {
this.idling = false;
}
@@ -155,10 +169,49 @@ class SMTPPool extends node_events_1.EventEmitter {
return true;
}
/**
* Closes all connections in the pool. If there is a message being sent, the connection
* is closed later
* Fails a queued or assigned entry when its signal aborts: removes it from the queue, or
* closes the connection delivering it, so other deliveries in the pool can continue.
* Returns a function that removes the listener.
* @internal
*/
close() {
_watchAbortSignal(entry, signal, isPending) {
const onAbort = () => {
if (!isPending()) {
return;
}
const index = this._queue.indexOf(entry);
if (index !== -1) {
this._queue.splice(index, 1);
}
const resource = entry.resource;
if (resource && resource.queueEntry === entry) {
// Detach before closing: the close handler must not retry this message.
resource.queueEntry = false;
resource.close();
}
try {
entry.callback(errors.createAbortError(signal));
}
finally {
// Removing a queued entry can make the pool idle again.
setImmediate(() => this._processMessages());
}
};
signal.addEventListener('abort', onAbort, { once: true });
if (signal.aborted) {
setImmediate(onAbort);
}
return () => signal.removeEventListener('abort', onAbort);
}
/**
* Closes the pool. Idle connections are closed at once and a connection in the middle of a
* delivery finishes it first, unless `force` is set: then it is closed too and its message
* fails. `force` is for a caller that has given up on a delivery, such as one a server is
* stalling by trickling its replies, which no socket timeout notices.
*
* @param options.force - Also close connections that are delivering a message
*/
close(options) {
let connection;
const len = this._connections.length;
this._closed = true;
@@ -169,9 +222,10 @@ class SMTPPool extends node_events_1.EventEmitter {
if (!len && !this._queue.length) {
return;
}
// remove all available connections
// remove all available connections, and with `force` the busy ones too
const force = !!options?.force;
for (let i = len - 1; i >= 0; i--) {
if (this._connections[i] && this._connections[i].available) {
if (this._connections[i] && (force || this._connections[i].available)) {
connection = this._connections[i];
connection.close();
this.logger.info({
@@ -249,6 +303,7 @@ class SMTPPool extends node_events_1.EventEmitter {
this.emit('idle');
}
const entry = (connection.queueEntry = this._queue.shift());
entry.resource = connection;
entry.messageId = (connection.queueEntry.mail.message.getHeader('message-id') || '').replace(/[<>\s]/g, '');
connection.available = false;
this.logger.debug({
@@ -356,7 +411,9 @@ class SMTPPool extends node_events_1.EventEmitter {
setTimeout(() => {
let delay = 0;
if (connection.queueEntry) {
if (this._shouldRequeuOnConnectionClose(connection.queueEntry)) {
// a closed pool (a forced close ends a delivery on purpose) fails the
// message rather than queueing it for a retry that would never run
if (!this._closed && this._shouldRequeuOnConnectionClose(connection.queueEntry)) {
delay = this._requeueEntryOnConnectionClose(connection);
}
else {
@@ -418,6 +475,7 @@ class SMTPPool extends node_events_1.EventEmitter {
messageId: connection.queueEntry.messageId,
action: 'requeue'
}, 'Re-queued message <%s> for #%s. Attempt: #%s', connection.queueEntry.messageId, connection.id, connection.queueEntry.requeueAttempts);
connection.queueEntry.resource = undefined;
this._queue.unshift(connection.queueEntry);
connection.queueEntry = false;
return delay;
+26 -4
View File
@@ -86,6 +86,7 @@ class PoolResource extends node_events_1.EventEmitter {
}
this._connection = false;
this._connected = false;
this._closed = false;
this.messages = 0;
this.available = true;
this._failed = false;
@@ -113,6 +114,10 @@ class PoolResource extends node_events_1.EventEmitter {
// the proxy handshake, if any, counts against connectionTimeout as well
const connectStartedAt = Date.now();
this.pool.getSocket(Object.assign({}, this.options, { connectStartedAt }), (err, socketOptions) => {
if (this._closed) {
socketOptions && socketOptions.connection?.destroy();
return;
}
if (err) {
// nothing was connected, so no 'close' event is coming that would free the
// slot this resource holds in the pool, report the failure the way a failed
@@ -136,7 +141,7 @@ class PoolResource extends node_events_1.EventEmitter {
this.connection = new index_js_1.default(options);
this.connection._connectStartedAt = connectStartedAt;
this.connection.on('error', (err) => {
if (this._sending) {
if (this._closed || this._sending) {
// the send callback gets the same error and decides what it means for the message
return;
}
@@ -150,7 +155,7 @@ class PoolResource extends node_events_1.EventEmitter {
return;
}
this._fail(err);
if (returned) {
if (returned || this._closed) {
return;
}
returned = true;
@@ -161,7 +166,7 @@ class PoolResource extends node_events_1.EventEmitter {
returned = true;
});
this.connection.connect(err => {
if (returned) {
if (returned || this._closed) {
return;
}
if (err) {
@@ -172,7 +177,7 @@ class PoolResource extends node_events_1.EventEmitter {
}
if (this.auth && (this.connection.allowsAuth || options.forceAuth)) {
this.connection.login(this.auth, err => {
if (returned) {
if (returned || this._closed) {
return;
}
returned = true;
@@ -200,6 +205,9 @@ class PoolResource extends node_events_1.EventEmitter {
* @param callback Callback function
*/
send(mail, callback) {
if (this._closed) {
return;
}
if (!this._connected) {
return this.connect(err => {
if (err) {
@@ -231,6 +239,9 @@ class PoolResource extends node_events_1.EventEmitter {
const reused = this.messages > 0;
const messageStream = mail.message.createReadStream();
this.connection.send(envelope, messageStream, (err, info) => {
if (mail.data.signal?.aborted) {
return;
}
this._sending = false;
this.messages++;
if (err) {
@@ -277,6 +288,9 @@ class PoolResource extends node_events_1.EventEmitter {
* @internal
*/
_release() {
if (this._closed) {
return;
}
if (this.messages >= this.options.maxMessages) {
const err = new Error('Resource exhausted');
err.code = errors.EMAXLIMIT;
@@ -285,6 +299,9 @@ class PoolResource extends node_events_1.EventEmitter {
return;
}
this.pool._checkRateLimit(() => {
if (this._closed) {
return;
}
this.available = true;
this._startIdleTimer();
this.emit('available');
@@ -327,6 +344,11 @@ class PoolResource extends node_events_1.EventEmitter {
* Closes the connection
*/
close() {
if (this._closed) {
return;
}
this._closed = true;
this.available = false;
this._connected = false;
this._stopIdleTimer();
if (this.auth && this.auth.oauth2) {