mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2026-11-21 21:06:12 +07:00
node_modules: update (#362)
Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com>
This commit is contained in:
1 parent
4a48500d96
commit
aefdaa6a6c
49 files changed
+1316
-295
No files matched your search
+70
-12
@@ -18,6 +18,7 @@ const REQUEUE_MAX_DELAY = 2000;
|
||||
class SMTPPool extends EventEmitter {
|
||||
constructor(options) {
|
||||
super();
|
||||
this.supportsAbortSignal = true;
|
||||
options = options || {};
|
||||
if (typeof options === 'string') {
|
||||
options = {
|
||||
@@ -96,20 +97,33 @@ class SMTPPool extends 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;
|
||||
}
|
||||
@@ -117,10 +131,49 @@ class SMTPPool extends 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;
|
||||
@@ -131,9 +184,10 @@ class SMTPPool extends 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({
|
||||
@@ -211,6 +265,7 @@ class SMTPPool extends 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({
|
||||
@@ -318,7 +373,9 @@ class SMTPPool extends 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 {
|
||||
@@ -380,6 +437,7 @@ class SMTPPool extends 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;
|
||||
|
||||
Reference in new issue
Block a user