emailengine-app 2.79.2 → 2.79.4

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/server.js CHANGED
@@ -1160,11 +1160,21 @@ let spawnWorker = async (type, opts) => {
1160
1160
  onlineWorkers.delete(worker);
1161
1161
  metrics.threadStops.inc();
1162
1162
 
1163
+ // One classification for the whole handler: a suspended worker type and a clean exit
1164
+ // code are both deliberate, anything else is a worker that died.
1165
+ const unexpectedExit = exitCode !== 0 && !suspendedWorkerTypes.has(type);
1166
+
1167
+ // What a worker death cost - dropped API calls and offline accounts - is only ever
1168
+ // stated by the lines below, and they fire on deliberate exits too. The unexpected
1169
+ // case is the one an operator has to see, and most deployments run above info, so
1170
+ // that case logs at warn while a clean or requested stop stays at info.
1171
+ const exitLevel = unexpectedExit && !isClosing ? 'warn' : 'info';
1172
+
1163
1173
  // Fail any in-flight calls routed to this worker right away, so callers
1164
1174
  // get a fast retryable error instead of hanging until their own timeout.
1165
1175
  let rejectedCalls = rejectWorkerCalls(callQueue, worker, WORKER_DIED_RESP_ERR);
1166
1176
  if (rejectedCalls) {
1167
- logger.info({ msg: 'Rejected in-flight calls for exited worker', type, threadId: worker.threadId, rejectedCalls });
1177
+ logger[exitLevel]({ msg: 'Rejected in-flight calls for exited worker', type, threadId: worker.threadId, rejectedCalls });
1168
1178
  }
1169
1179
 
1170
1180
  workers.get(type).delete(worker);
@@ -1188,7 +1198,7 @@ let spawnWorker = async (type, opts) => {
1188
1198
  unassigned.add(account);
1189
1199
  }
1190
1200
 
1191
- logger.info({
1201
+ logger[exitLevel]({
1192
1202
  msg: 'Worker exited, moving accounts to unassigned',
1193
1203
  accounts: accountList.size,
1194
1204
  exitCode
@@ -1204,7 +1214,9 @@ let spawnWorker = async (type, opts) => {
1204
1214
 
1205
1215
  // Check if all workers have exited (Redis reconnection scenario)
1206
1216
  if (availableIMAPWorkers.size === 0) {
1207
- logger.info({
1217
+ // Account tracking was lost fleet-wide - the same class of event as the
1218
+ // warn above, and equally invisible to an operator running above info
1219
+ logger.warn({
1208
1220
  msg: 'All IMAP workers exited, reloading accounts from Redis for reassignment'
1209
1221
  });
1210
1222
 
@@ -1215,7 +1227,7 @@ let spawnWorker = async (type, opts) => {
1215
1227
  assigned.clear();
1216
1228
  workerAssigned = new WeakMap();
1217
1229
 
1218
- logger.info({
1230
+ logger.warn({
1219
1231
  msg: 'Reloaded accounts from Redis',
1220
1232
  accountCount: accounts.length
1221
1233
  });
@@ -1251,7 +1263,7 @@ let spawnWorker = async (type, opts) => {
1251
1263
  }
1252
1264
  }, 10000); // 10 second timeout
1253
1265
 
1254
- logger.info({
1266
+ logger[exitLevel]({
1255
1267
  msg: 'Worker exited, waiting for restart before reassignment',
1256
1268
  accounts: unassigned.size,
1257
1269
  expectedWorkers: config.workers.imap,
@@ -1265,13 +1277,13 @@ let spawnWorker = async (type, opts) => {
1265
1277
  }
1266
1278
 
1267
1279
  // Log worker exit
1268
- if (suspendedWorkerTypes.has(type)) {
1280
+ if (unexpectedExit) {
1281
+ logger.error({ msg: 'Worker unexpectedly exited', exitCode, type });
1282
+ } else if (suspendedWorkerTypes.has(type)) {
1269
1283
  logger.info({ msg: 'Worker thread terminated', exitCode, type });
1270
- } else if (exitCode === 0) {
1284
+ } else {
1271
1285
  // Clean exit, e.g. the deliberate exit-for-restart after a Redis reconnection
1272
1286
  logger.info({ msg: 'Worker exited', exitCode, type });
1273
- } else {
1274
- logger.error({ msg: 'Worker unexpectedly exited', exitCode, type });
1275
1287
  }
1276
1288
 
1277
1289
  // Respawn worker after delay, preserving any spawn options (e.g. API worker index).