node_modules: update (#338)

Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com>
This commit is contained in:
Dawid Dziurlaanddawidd6 authored and GitHub committed 2026-10-03 10:23:35 +02:00
1 parent e1936242ed
commit a9c5eb6c35
39 files changed
+799 -388

No files matched your search

+2 -1
View File
@@ -17,7 +17,7 @@ export interface SMTPPoolOptions extends SMTPTransportOptions {
rateLimit?: number | undefined;
/** Time window for rateLimit in milliseconds, defaults to 1000 */
rateDelta?: number | undefined;
/** How many times a message is requeued when its connection closes while sending, unlimited when not set or negative */
/** How many times a message is requeued when its connection closes while sending, defaults to 5, a negative value means unlimited */
maxRequeues?: number | undefined;
}
/**
@@ -26,6 +26,7 @@ export interface SMTPPoolOptions extends SMTPTransportOptions {
export type SMTPPoolResolvedOptions = SMTPPoolOptions & {
maxConnections: number;
maxMessages: number;
maxRequeues: number;
};
/**
* Result of a message sent through the pool, same as for the SMTP transport
+31 -5
View File
@@ -5,6 +5,10 @@ import wellKnown from '../well-known/index.js';
import * as shared from '../shared/index.js';
import * as errors from '../errors.js';
import * as packageData from '../package-info.js';
/** First delay before a requeued message is retried, doubled on every further requeue */
const REQUEUE_BASE_DELAY = 50;
/** Upper bound for the requeue delay */
const REQUEUE_MAX_DELAY = 2000;
/**
* Creates a SMTP pool transport object for Nodemailer
*
@@ -36,6 +40,8 @@ class SMTPPool extends EventEmitter {
);
this.options.maxConnections = this.options.maxConnections || 5;
this.options.maxMessages = this.options.maxMessages || 100;
// a default bound, a server that closes every connection before the greeting would otherwise be retried forever
this.options.maxRequeues = typeof this.options.maxRequeues === 'number' ? this.options.maxRequeues : 5;
this.logger = shared.getLogger(this.options, {
component: this.options.component || 'smtp-pool'
});
@@ -79,6 +85,10 @@ class SMTPPool extends EventEmitter {
*/
send(mail, callback) {
if (this._closed) {
// Mail.sendMail ignores the return value, so without a callback its promise would never settle
const err = new Error('Connection pool was closed');
err.code = errors.ECONNECTION;
setImmediate(() => callback(err));
return false;
}
this._queue.push({
@@ -292,15 +302,22 @@ class SMTPPool extends EventEmitter {
// Note that we must wait a bit.. because the callback of the 'error' handler might be called
// in the next event loop
setTimeout(() => {
let delay = 0;
if (connection.queueEntry) {
if (this._shouldRequeuOnConnectionClose(connection.queueEntry)) {
this._requeueEntryOnConnectionClose(connection);
delay = this._requeueEntryOnConnectionClose(connection);
}
else {
this._failDeliveryOnConnectionClose(connection);
}
}
this._continueProcessing();
if (delay) {
// back off, a server that keeps dropping connections is not hammered
setTimeout(() => this._continueProcessing(), delay);
}
else {
this._continueProcessing();
}
}, 50);
}
else {
@@ -315,7 +332,7 @@ class SMTPPool extends EventEmitter {
}
/** @internal */
_shouldRequeuOnConnectionClose(queueEntry) {
if (this.options.maxRequeues === undefined || this.options.maxRequeues < 0) {
if (this.options.maxRequeues < 0) {
return true;
}
return queueEntry.requeueAttempts < this.options.maxRequeues;
@@ -324,7 +341,9 @@ class SMTPPool extends EventEmitter {
_failDeliveryOnConnectionClose(connection) {
if (connection.queueEntry && connection.queueEntry.callback) {
try {
connection.queueEntry.callback(new Error('Reached maximum number of retries after connection was closed'));
const err = new Error('Reached maximum number of retries after connection was closed');
err.code = errors.ECONNECTION;
connection.queueEntry.callback(err);
}
catch (E) {
this.logger.error({
@@ -339,6 +358,7 @@ class SMTPPool extends EventEmitter {
}
/** @internal */
_requeueEntryOnConnectionClose(connection) {
const delay = Math.min(REQUEUE_BASE_DELAY * 2 ** connection.queueEntry.requeueAttempts, REQUEUE_MAX_DELAY);
connection.queueEntry.requeueAttempts += 1;
this.logger.debug({
tnx: 'pool',
@@ -348,6 +368,7 @@ class SMTPPool extends EventEmitter {
}, 'Re-queued message <%s> for #%s. Attempt: #%s', connection.queueEntry.messageId, connection.id, connection.queueEntry.requeueAttempts);
this._queue.unshift(connection.queueEntry);
connection.queueEntry = false;
return delay;
}
/**
* Continue to process message if the pool hasn't closed
@@ -468,10 +489,15 @@ class SMTPPool extends EventEmitter {
connection.quit();
return done(null, true);
};
connection.connect(() => {
connection.connect(err => {
if (returned) {
return;
}
if (err) {
returned = true;
connection.close();
return done(err);
}
if (auth && (connection.allowsAuth || options.forceAuth)) {
connection.login(auth, err => {
if (returned) {
+27 -29
View File
@@ -28,7 +28,7 @@ export default class PoolResource extends EventEmitter {
method: 'XOAUTH2'
};
oauth2.on('token', (token) => this.pool.mailer.emit('token', token));
oauth2.on('error', err => this.emit('error', err));
oauth2.on('error', err => this._fail(err));
break;
}
default:
@@ -51,6 +51,19 @@ export default class PoolResource extends EventEmitter {
this._connected = false;
this.messages = 0;
this.available = true;
this._failed = false;
}
/**
* Emits 'error' for the first failure only. A dead resource can report the same failure more
* than once (the connection error, then the send callback), the pool handles it once
* @internal
*/
_fail(err) {
if (this._failed) {
return;
}
this._failed = true;
this.emit('error', err);
}
/**
* Initiates a connection to the SMTP server
@@ -63,7 +76,7 @@ export default class PoolResource extends EventEmitter {
// 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
// login does
this.emit('error', err);
this._fail(err);
return callback(err);
}
let returned = false;
@@ -80,8 +93,8 @@ export default class PoolResource extends EventEmitter {
options = Object.assign(assign(false, options), socketOptions);
}
this.connection = new SMTPConnection(options);
this.connection.once('error', err => {
this.emit('error', err);
this.connection.on('error', err => {
this._fail(err);
if (returned) {
return;
}
@@ -90,31 +103,16 @@ export default class PoolResource extends EventEmitter {
});
this.connection.once('end', () => {
this.close();
returned = true;
});
this.connection.connect(err => {
if (returned) {
return;
}
returned = true;
const timer = setTimeout(() => {
if (returned) {
return;
}
// still have not returned, this means we have an unexpected connection close
const err = new Error('Unexpected socket close');
if (this.connection && this.connection.upgrading) {
// starttls connection errors
err.code = errors.ETLS;
}
callback(err);
}, 1000);
try {
timer.unref();
}
catch (_E) {
// Ignore. Happens on envs with non-node timer implementation
}
});
this.connection.connect(() => {
if (returned) {
if (err) {
// a close before the greeting, the 'end' that follows closes this resource
// and the pool requeues or fails the entry, bounded by maxRequeues
returned = true;
return;
}
if (this.auth && (this.connection.allowsAuth || options.forceAuth)) {
@@ -125,7 +123,7 @@ export default class PoolResource extends EventEmitter {
returned = true;
if (err) {
this.connection.close();
this.emit('error', err);
this._fail(err);
return callback(err);
}
this._connected = true;
@@ -177,7 +175,7 @@ export default class PoolResource extends EventEmitter {
this.messages++;
if (err) {
this.connection.close();
this.emit('error', err);
this._fail(err);
return callback(err);
}
info.envelope = {
@@ -190,7 +188,7 @@ export default class PoolResource extends EventEmitter {
const err = new Error('Resource exhausted');
err.code = errors.EMAXLIMIT;
this.connection.close();
this.emit('error', err);
this._fail(err);
}
else {
this.pool._checkRateLimit(() => {