mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2026-10-09 09:59:45 +07:00
node_modules: update (#338)
Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com>
This commit is contained in:
1 parent
e1936242ed
commit
a9c5eb6c35
39 files changed
+799
-388
No files matched your search
+31
-5
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user