mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2026-11-22 05:25:29 +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
+10
-3
@@ -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
@@ -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;
|
||||
|
||||
+26
-4
@@ -48,6 +48,7 @@ export default class PoolResource extends EventEmitter {
|
||||
}
|
||||
this._connection = false;
|
||||
this._connected = false;
|
||||
this._closed = false;
|
||||
this.messages = 0;
|
||||
this.available = true;
|
||||
this._failed = false;
|
||||
@@ -75,6 +76,10 @@ export default class PoolResource extends 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
|
||||
@@ -98,7 +103,7 @@ export default class PoolResource extends EventEmitter {
|
||||
this.connection = new SMTPConnection(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;
|
||||
}
|
||||
@@ -112,7 +117,7 @@ export default class PoolResource extends EventEmitter {
|
||||
return;
|
||||
}
|
||||
this._fail(err);
|
||||
if (returned) {
|
||||
if (returned || this._closed) {
|
||||
return;
|
||||
}
|
||||
returned = true;
|
||||
@@ -123,7 +128,7 @@ export default class PoolResource extends EventEmitter {
|
||||
returned = true;
|
||||
});
|
||||
this.connection.connect(err => {
|
||||
if (returned) {
|
||||
if (returned || this._closed) {
|
||||
return;
|
||||
}
|
||||
if (err) {
|
||||
@@ -134,7 +139,7 @@ export default class PoolResource extends EventEmitter {
|
||||
}
|
||||
if (this.auth && (this.connection.allowsAuth || options.forceAuth)) {
|
||||
this.connection.login(this.auth, err => {
|
||||
if (returned) {
|
||||
if (returned || this._closed) {
|
||||
return;
|
||||
}
|
||||
returned = true;
|
||||
@@ -162,6 +167,9 @@ export default class PoolResource extends EventEmitter {
|
||||
* @param callback Callback function
|
||||
*/
|
||||
send(mail, callback) {
|
||||
if (this._closed) {
|
||||
return;
|
||||
}
|
||||
if (!this._connected) {
|
||||
return this.connect(err => {
|
||||
if (err) {
|
||||
@@ -193,6 +201,9 @@ export default class PoolResource extends 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) {
|
||||
@@ -239,6 +250,9 @@ export default class PoolResource extends EventEmitter {
|
||||
* @internal
|
||||
*/
|
||||
_release() {
|
||||
if (this._closed) {
|
||||
return;
|
||||
}
|
||||
if (this.messages >= this.options.maxMessages) {
|
||||
const err = new Error('Resource exhausted');
|
||||
err.code = errors.EMAXLIMIT;
|
||||
@@ -247,6 +261,9 @@ export default class PoolResource extends EventEmitter {
|
||||
return;
|
||||
}
|
||||
this.pool._checkRateLimit(() => {
|
||||
if (this._closed) {
|
||||
return;
|
||||
}
|
||||
this.available = true;
|
||||
this._startIdleTimer();
|
||||
this.emit('available');
|
||||
@@ -289,6 +306,11 @@ export default class PoolResource extends 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) {
|
||||
|
||||
Reference in new issue
Block a user