emailengine-app 2.83.1 → 2.83.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/workers/imap.js CHANGED
@@ -418,10 +418,17 @@ class ConnectionHandler {
418
418
  this.assignTokens.delete(account);
419
419
  if (this.accounts.has(account)) {
420
420
  let accountObject = this.accounts.get(account);
421
- if (accountObject.connection) {
422
- await accountObject.connection.delete();
421
+ try {
422
+ if (accountObject.connection) {
423
+ await accountObject.connection.delete();
424
+ }
425
+ } finally {
426
+ // The account record is already gone and nothing retries the delete, so an entry
427
+ // left behind by a failed teardown would stay registered for the worker's lifetime
428
+ if (this.accounts.get(account) === accountObject) {
429
+ this.accounts.delete(account);
430
+ }
423
431
  }
424
- this.accounts.delete(account);
425
432
  }
426
433
  }
427
434
 
package/workers/smtp.js CHANGED
@@ -32,6 +32,10 @@ config.service = config.service || {};
32
32
 
33
33
  const { DEFAULT_MAX_SMTP_MESSAGE_SIZE } = require('../lib/consts');
34
34
 
35
+ // On shutdown, how long open sessions get before they are told 421 and closed. Shorter than
36
+ // WORKER_DRAIN_TIMEOUT in server.js, so the 421 goes out before the thread is terminated
37
+ const SMTP_CLOSE_TIMEOUT = 5 * 1000;
38
+
35
39
  const DEFAULT_EENGINE_TIMEOUT = 10 * 1000;
36
40
 
37
41
  const MAX_SMTP_MESSAGE_SIZE = getByteSize(readEnvValue('EENGINE_MAX_SMTP_MESSAGE_SIZE') || config.smtp.maxMessageSize) || DEFAULT_MAX_SMTP_MESSAGE_SIZE;
@@ -133,7 +137,8 @@ async function init() {
133
137
  banner: 'EmailEngine MSA',
134
138
  size: MAX_SMTP_MESSAGE_SIZE,
135
139
  maxClients: SMTP_MAX_CLIENTS,
136
- useProxy: await settings.get('smtpServerProxy')
140
+ useProxy: await settings.get('smtpServerProxy'),
141
+ closeTimeout: SMTP_CLOSE_TIMEOUT
137
142
  };
138
143
 
139
144
  // Reads what the API worker provisioned; this one never orders a certificate itself.
@@ -326,6 +331,16 @@ async function onCommand(command) {
326
331
 
327
332
  case 'smtpReloadCertificates':
328
333
  return await reloadCertificates();
334
+
335
+ // Shutdown drain. Signals reach the main thread only, so server.js forwards them here.
336
+ // Stops accepting connections and lets a submission halfway through DATA be queued and
337
+ // answered, instead of cutting it at process exit: a client that never sees the 250 for
338
+ // a message that was already queued sends it again
339
+ case 'close':
340
+ if (smtpServer) {
341
+ await new Promise(resolve => smtpServer.close(resolve));
342
+ }
343
+ return true;
329
344
  default:
330
345
  logger.debug({ msg: 'Unhandled command', command });
331
346
  return 999;