emailengine-app 2.79.7 → 2.79.9
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/.github/dependabot.yml +22 -0
- package/.github/workflows/test.yml +39 -0
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +37 -0
- package/DOCKER_DEPLOYMENT.md +8 -7
- package/Dockerfile +35 -11
- package/bin/emailengine.js +29 -13
- package/config/default.toml +15 -4
- package/copy-static-files.sh +23 -5
- package/data/google-crawlers.json +7 -1
- package/docker-compose.yml +12 -3
- package/install.sh +2 -0
- package/lib/account.js +26 -1
- package/lib/api-routes/account-routes.js +14 -3
- package/lib/api-routes/bull-board-routes.js +3 -2
- package/lib/api-routes/mailbox-routes.js +4 -1
- package/lib/api-routes/message-routes.js +6 -5
- package/lib/api-routes/outbox-routes.js +7 -4
- package/lib/api-routes/route-helpers.js +8 -0
- package/lib/api-routes/settings-routes.js +34 -25
- package/lib/api-routes/stats-routes.js +8 -1
- package/lib/api-routes/submit-routes.js +2 -1
- package/lib/api-routes/template-routes.js +3 -2
- package/lib/auth-token.js +73 -2
- package/lib/autodetect-imap-settings.js +33 -25
- package/lib/bounce-detect.js +45 -0
- package/lib/consts.js +13 -2
- package/lib/egress-fetch.js +133 -0
- package/lib/egress-filter.js +39 -4
- package/lib/email-client/base-client.js +274 -24
- package/lib/email-client/gmail/gmail-api.js +15 -7
- package/lib/email-client/gmail-client.js +121 -64
- package/lib/email-client/imap/mailbox.js +18 -59
- package/lib/email-client/imap-client.js +53 -29
- package/lib/email-client/notification-handler.js +11 -2
- package/lib/email-client/outlook/graph-api.js +106 -90
- package/lib/email-client/outlook-client.js +222 -106
- package/lib/export.js +35 -2
- package/lib/generate-text-preview.js +10 -5
- package/lib/handlebars-helpers.js +129 -0
- package/lib/headers-rewriter.js +1 -1
- package/lib/imap-proxy-auth.js +41 -21
- package/lib/imapproxy/imap-core/README.md +1 -0
- package/lib/imapproxy/imap-core/lib/tls-options.js +5 -46
- package/lib/imapproxy/imap-server.js +9 -10
- package/lib/llm-pre-process.js +4 -1
- package/lib/mcp/json-schema.js +50 -2
- package/lib/openapi/index.js +3 -0
- package/lib/outbox.js +50 -8
- package/lib/pre-process.js +4 -1
- package/lib/rate-limit.js +23 -4
- package/lib/rewrite-text-nodes.js +12 -1
- package/lib/schemas.js +37 -8
- package/lib/security-headers.js +396 -0
- package/lib/sentry.js +36 -4
- package/lib/settings.js +19 -1
- package/lib/smtp-auth.js +86 -7
- package/lib/sso.js +13 -3
- package/lib/submit-progress.js +29 -0
- package/lib/templates.js +11 -0
- package/lib/tools.js +361 -173
- package/lib/ui-routes/account-routes.js +73 -13
- package/lib/ui-routes/admin-config-routes.js +7 -21
- package/lib/ui-routes/admin-entities-routes.js +42 -12
- package/lib/ui-routes/auth-routes.js +87 -28
- package/lib/ui-routes/dashboard-routes.js +1 -1
- package/lib/ui-routes/export-routes.js +4 -0
- package/lib/ui-routes/internals-routes.js +2 -0
- package/lib/ui-routes/mcp-consent-routes.js +12 -2
- package/lib/ui-routes/network-config-routes.js +6 -5
- package/lib/ui-routes/oauth-config-routes.js +12 -1
- package/lib/ui-routes/route-helpers.js +65 -14
- package/lib/ui-routes/settings-page.js +10 -0
- package/lib/ui-routes/smtp-test-routes.js +7 -0
- package/lib/ui-routes/suppression-list-routes.js +16 -5
- package/lib/ui-routes/unsubscribe-routes.js +22 -3
- package/lib/webhook-egress.js +5 -0
- package/lib/webhooks.js +14 -2
- package/package.json +23 -26
- package/sbom.json +1 -1
- package/server.js +100 -71
- package/static/css/flyonui.css +1 -1
- package/static/js/ace/css/ace.css +1462 -0
- package/static/js/ace/css/kuroir-1.png +0 -0
- package/static/js/ace/css/kuroir-2.png +0 -0
- package/static/js/ace/css/main-1.png +0 -0
- package/static/js/ace/css/main-10.svg +4 -0
- package/static/js/ace/css/main-11.svg +5 -0
- package/static/js/ace/css/main-12.svg +4 -0
- package/static/js/ace/css/main-13.png +0 -0
- package/static/js/ace/css/main-14.png +0 -0
- package/static/js/ace/css/main-15.png +0 -0
- package/static/js/ace/css/main-16.png +0 -0
- package/static/js/ace/css/main-17.png +0 -0
- package/static/js/ace/css/main-18.png +0 -0
- package/static/js/ace/css/main-19.png +0 -0
- package/static/js/ace/css/main-2.png +0 -0
- package/static/js/ace/css/main-20.png +0 -0
- package/static/js/ace/css/main-21.png +0 -0
- package/static/js/ace/css/main-22.png +0 -0
- package/static/js/ace/css/main-23.png +0 -0
- package/static/js/ace/css/main-24.png +0 -0
- package/static/js/ace/css/main-25.svg +1 -0
- package/static/js/ace/css/main-26.png +0 -0
- package/static/js/ace/css/main-3.png +0 -0
- package/static/js/ace/css/main-4.png +0 -0
- package/static/js/ace/css/main-5.svg +7 -0
- package/static/js/ace/css/main-6.svg +9 -0
- package/static/js/ace/css/main-7.svg +7 -0
- package/static/js/ace/css/main-8.svg +9 -0
- package/static/js/ace/css/main-9.svg +6 -0
- package/static/js/ace/css/theme/kuroir.css +78 -0
- package/static/js/ace/css/theme/tomorrow_night.css +128 -0
- package/static/js/ace/css/theme/tomorrow_night_eighties.css +128 -0
- package/static/js/ace/css/theme/xcode.css +106 -0
- package/static/js/ace/css/tomorrow_night-1.png +0 -0
- package/static/js/ace/css/tomorrow_night-2.png +0 -0
- package/static/js/ace/css/tomorrow_night_eighties-1.png +0 -0
- package/static/js/ace/css/tomorrow_night_eighties-2.png +0 -0
- package/static/js/ace/css/xcode-1.png +0 -0
- package/static/js/ace/css/xcode-2.png +0 -0
- package/static/js/ee-client.js +256 -102
- package/static/js/public.js +7 -0
- package/static/js/ui.js +32 -0
- package/static/licenses.html +338 -298
- package/static/vendor/simplewebauthn/browser.min.js +2 -2
- package/translations/messages.pot +158 -112
- package/views/account/passkeys.hbs +8 -0
- package/views/account/password.hbs +11 -0
- package/views/account/security.hbs +18 -7
- package/views/accounts/account.hbs +21 -38
- package/views/accounts/browse.hbs +3 -1
- package/views/accounts/edit.hbs +1 -1
- package/views/accounts/register/imap-server.hbs +11 -3
- package/views/config/ai.hbs +3 -1
- package/views/config/branding.hbs +4 -2
- package/views/config/document-store/chat.hbs +1 -1
- package/views/config/document-store/index.hbs +1 -1
- package/views/config/email-processing.hbs +2 -0
- package/views/config/imap-proxy.hbs +3 -1
- package/views/config/license.hbs +1 -1
- package/views/config/logging.hbs +3 -1
- package/views/config/mcp.hbs +3 -1
- package/views/config/network.hbs +16 -16
- package/views/config/oauth/app.hbs +4 -4
- package/views/config/security.hbs +2 -0
- package/views/config/service.hbs +3 -1
- package/views/config/smtp.hbs +3 -1
- package/views/config/webhooks.hbs +4 -2
- package/views/error.hbs +10 -2
- package/views/internals/index.hbs +1 -1
- package/views/layout/app.hbs +9 -14
- package/views/layout/login.hbs +1 -1
- package/views/layout/prompt.hbs +1 -1
- package/views/layout/public.hbs +1 -1
- package/views/legal.hbs +1 -1
- package/views/mcp/authorize.hbs +1 -1
- package/views/partials/ace_assets.hbs +13 -0
- package/views/partials/add_account_modal.hbs +1 -1
- package/views/partials/address_list.hbs +4 -4
- package/views/partials/filter_editor_js.hbs +3 -3
- package/views/partials/gateway_js.hbs +1 -1
- package/views/partials/oauth_form.hbs +6 -6
- package/views/partials/public_theme_init.hbs +1 -1
- package/views/partials/template_form.hbs +2 -2
- package/views/partials/test_send.hbs +7 -4
- package/views/partials/theme_init.hbs +1 -1
- package/views/partials/ui/details.hbs +2 -2
- package/views/partials/ui/env-managed-alert.hbs +19 -0
- package/views/partials/webhook_form.hbs +1 -1
- package/views/partials/webhooks_editor_functions.hbs +1 -1
- package/views/reference/redirect.hbs +1 -1
- package/views/templates/template.hbs +2 -2
- package/views/tokens/new.hbs +1 -1
- package/views/unsubscribe.hbs +7 -1
- package/views/webhooks/webhook.hbs +2 -2
- package/workers/api.js +179 -175
- package/workers/export.js +1 -5
- package/workers/imap.js +33 -6
- package/workers/smtp.js +19 -43
- package/workers/submit.js +31 -13
- package/workers/webhooks.js +9 -24
- package/lib/reconnection-manager.js +0 -106
- package/static/front/EmailEngine_logo_horiz.png +0 -0
- package/static/front/EmailEngine_logo_vert.png +0 -0
- package/static/front/index.html +0 -57
- package/static/front/logo.png +0 -0
- package/static/vendor/handlebars/handlebars.min-v4.7.9.js +0 -29
package/server.js
CHANGED
|
@@ -30,11 +30,12 @@ try {
|
|
|
30
30
|
// Set process title for easier identification in process lists
|
|
31
31
|
process.title = 'emailengine';
|
|
32
32
|
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
// EmailEngine and its dependencies need Node 20 or newer, the same floor the engines field in
|
|
34
|
+
// package.json declares. Checked before anything is required, so an older runtime gets this line
|
|
35
|
+
// instead of a syntax error from a dependency. The check used to be a structuredClone probe, which
|
|
36
|
+
// only caught Node 16 and older.
|
|
37
|
+
if (Number(process.versions.node.split('.')[0]) < 20) {
|
|
38
|
+
console.error(`Node.js version ${process.version} is not supported. Please upgrade to Node.js 20 or later.`);
|
|
38
39
|
process.exit(1);
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -1075,7 +1076,8 @@ async function sendWebhook(account, event, data) {
|
|
|
1075
1076
|
* Spawn a new worker thread of the specified type
|
|
1076
1077
|
* @param {string} type - Worker type (imap, api, webhooks, submit, documents, smtp, imapProxy)
|
|
1077
1078
|
* @param {Object} [opts] - Optional spawn options
|
|
1078
|
-
* @param {Object} [opts.workerData] - Data passed to the worker thread (e.g. API worker index)
|
|
1079
|
+
* @param {Object} [opts.workerData] - Data passed to the worker thread (e.g. API worker index). The
|
|
1080
|
+
* proxy in effect is added for every type, see lib/tools.js
|
|
1079
1081
|
* @returns {Promise<number|void>} Thread ID if successful
|
|
1080
1082
|
*/
|
|
1081
1083
|
let spawnWorker = async (type, opts) => {
|
|
@@ -1113,7 +1115,9 @@ let spawnWorker = async (type, opts) => {
|
|
|
1113
1115
|
let worker = new WorkerThread(pathlib.join(__dirname, 'workers', `${type.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`)}.js`), {
|
|
1114
1116
|
argv,
|
|
1115
1117
|
env: SHARE_ENV,
|
|
1116
|
-
|
|
1118
|
+
// every worker builds its HTTP dispatchers from the proxy in effect before its first line of
|
|
1119
|
+
// code runs (lib/tools.js); this thread resolved it from settings before spawning anything
|
|
1120
|
+
workerData: Object.assign({ httpProxyUrl: httpAgent.proxyUrl }, opts && opts.workerData),
|
|
1117
1121
|
trackUnmanagedFds: true
|
|
1118
1122
|
});
|
|
1119
1123
|
metrics.threadStarts.inc();
|
|
@@ -1502,18 +1506,19 @@ let spawnWorker = async (type, opts) => {
|
|
|
1502
1506
|
}
|
|
1503
1507
|
});
|
|
1504
1508
|
|
|
1505
|
-
// Forward settings changes to
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
if (
|
|
1509
|
-
|
|
1510
|
-
try {
|
|
1511
|
-
postMessage(worker, message);
|
|
1512
|
-
} catch (err) {
|
|
1513
|
-
logger.error({ msg: 'Unable to forward settings to worker', type, worker: worker.threadId, err });
|
|
1514
|
-
}
|
|
1515
|
-
});
|
|
1509
|
+
// Forward settings changes to every other worker type (the IMAP workers were
|
|
1510
|
+
// handled above); each reloads its HTTP proxy agent from the 'settings' message
|
|
1511
|
+
for (let [type, typeWorkers] of workers) {
|
|
1512
|
+
if (type === 'imap') {
|
|
1513
|
+
continue;
|
|
1516
1514
|
}
|
|
1515
|
+
typeWorkers.forEach(worker => {
|
|
1516
|
+
try {
|
|
1517
|
+
postMessage(worker, message);
|
|
1518
|
+
} catch (err) {
|
|
1519
|
+
logger.error({ msg: 'Unable to forward settings to worker', type, worker: worker.threadId, err });
|
|
1520
|
+
}
|
|
1521
|
+
});
|
|
1517
1522
|
}
|
|
1518
1523
|
return;
|
|
1519
1524
|
|
|
@@ -2368,6 +2373,14 @@ async function updateQueueCounters() {
|
|
|
2368
2373
|
* @param {Object} message - Command message
|
|
2369
2374
|
* @returns {Promise<*>} Command result
|
|
2370
2375
|
*/
|
|
2376
|
+
// Options shared by every OpenAI call. A function rather than a constant because httpAgent.fetch is
|
|
2377
|
+
// swapped when the proxy settings change. The plain agent rather than the retrying one: the library
|
|
2378
|
+
// keeps its own 429 retry.
|
|
2379
|
+
const openAiRequestOpts = () => ({
|
|
2380
|
+
verbose: getBoolean(process.env.EE_OPENAPI_VERBOSE),
|
|
2381
|
+
dispatcher: httpAgent.fetch
|
|
2382
|
+
});
|
|
2383
|
+
|
|
2371
2384
|
async function onCommand(worker, message) {
|
|
2372
2385
|
switch (message.cmd) {
|
|
2373
2386
|
case 'metrics':
|
|
@@ -2528,9 +2541,7 @@ async function onCommand(worker, message) {
|
|
|
2528
2541
|
|
|
2529
2542
|
// OpenAI integration commands - run in main process to avoid memory overhead
|
|
2530
2543
|
case 'generateSummary': {
|
|
2531
|
-
let requestOpts =
|
|
2532
|
-
verbose: getBoolean(process.env.EE_OPENAPI_VERBOSE)
|
|
2533
|
-
};
|
|
2544
|
+
let requestOpts = openAiRequestOpts();
|
|
2534
2545
|
|
|
2535
2546
|
let openAiAPIKey = message.data.openAiAPIKey || (await settings.get('openAiAPIKey'));
|
|
2536
2547
|
|
|
@@ -2588,9 +2599,7 @@ async function onCommand(worker, message) {
|
|
|
2588
2599
|
}
|
|
2589
2600
|
|
|
2590
2601
|
case 'generateEmbeddings': {
|
|
2591
|
-
let requestOpts =
|
|
2592
|
-
verbose: getBoolean(process.env.EE_OPENAPI_VERBOSE)
|
|
2593
|
-
};
|
|
2602
|
+
let requestOpts = openAiRequestOpts();
|
|
2594
2603
|
|
|
2595
2604
|
let openAiAPIKey = message.data.openAiAPIKey || (await settings.get('openAiAPIKey'));
|
|
2596
2605
|
|
|
@@ -2623,9 +2632,7 @@ async function onCommand(worker, message) {
|
|
|
2623
2632
|
}
|
|
2624
2633
|
|
|
2625
2634
|
case 'embeddingsQuery': {
|
|
2626
|
-
let requestOpts =
|
|
2627
|
-
verbose: getBoolean(process.env.EE_OPENAPI_VERBOSE)
|
|
2628
|
-
};
|
|
2635
|
+
let requestOpts = openAiRequestOpts();
|
|
2629
2636
|
|
|
2630
2637
|
let openAiAPIKey = message.data.openAiAPIKey || (await settings.get('openAiAPIKey'));
|
|
2631
2638
|
|
|
@@ -2694,9 +2701,7 @@ async function onCommand(worker, message) {
|
|
|
2694
2701
|
}
|
|
2695
2702
|
|
|
2696
2703
|
case 'questionQuery': {
|
|
2697
|
-
let requestOpts =
|
|
2698
|
-
verbose: getBoolean(process.env.EE_OPENAPI_VERBOSE)
|
|
2699
|
-
};
|
|
2704
|
+
let requestOpts = openAiRequestOpts();
|
|
2700
2705
|
|
|
2701
2706
|
let openAiAPIKey = message.data.openAiAPIKey || (await settings.get('openAiAPIKey'));
|
|
2702
2707
|
|
|
@@ -2729,9 +2734,7 @@ async function onCommand(worker, message) {
|
|
|
2729
2734
|
}
|
|
2730
2735
|
|
|
2731
2736
|
case 'generateChunkEmbeddings': {
|
|
2732
|
-
let requestOpts =
|
|
2733
|
-
verbose: getBoolean(process.env.EE_OPENAPI_VERBOSE)
|
|
2734
|
-
};
|
|
2737
|
+
let requestOpts = openAiRequestOpts();
|
|
2735
2738
|
|
|
2736
2739
|
let openAiAPIKey = message.data.openAiAPIKey || (await settings.get('openAiAPIKey'));
|
|
2737
2740
|
|
|
@@ -2752,9 +2755,7 @@ async function onCommand(worker, message) {
|
|
|
2752
2755
|
}
|
|
2753
2756
|
|
|
2754
2757
|
case 'openAiListModels': {
|
|
2755
|
-
let requestOpts =
|
|
2756
|
-
verbose: getBoolean(process.env.EE_OPENAPI_VERBOSE)
|
|
2757
|
-
};
|
|
2758
|
+
let requestOpts = openAiRequestOpts();
|
|
2758
2759
|
|
|
2759
2760
|
let openAiAPIKey = message.data.openAiAPIKey || (await settings.get('openAiAPIKey'));
|
|
2760
2761
|
|
|
@@ -3175,6 +3176,44 @@ process.on('SIGINT', () => {
|
|
|
3175
3176
|
|
|
3176
3177
|
// START APPLICATION
|
|
3177
3178
|
|
|
3179
|
+
/**
|
|
3180
|
+
* Waits for a fleet of spawned workers and tolerates a partial start: proceeds as long as at
|
|
3181
|
+
* least one worker reached 'ready' (the spawnWorker exit handler respawns any that failed;
|
|
3182
|
+
* letting such a rejection abort startup would exit the process while the respawn is pending).
|
|
3183
|
+
* Only a fleet that failed entirely is fatal - the thrown error rejects startApplication(), which
|
|
3184
|
+
* logs fatal and exits the process, preserving the original single-worker "no worker => exit"
|
|
3185
|
+
* behavior.
|
|
3186
|
+
*
|
|
3187
|
+
* @param {string} label - Worker type as it appears in the log lines ('API', 'IMAP')
|
|
3188
|
+
* @param {Promise[]} promises - spawnWorker() promises of the fleet
|
|
3189
|
+
* @param {Object} logFields - extra fields for the partial-failure log line (requested count etc.)
|
|
3190
|
+
* @returns {Promise<Array>} Thread IDs of the workers that reached 'ready'
|
|
3191
|
+
*/
|
|
3192
|
+
const settleWorkerFleet = async (label, promises, logFields) => {
|
|
3193
|
+
let results = await Promise.allSettled(promises);
|
|
3194
|
+
let threadIds = results.filter(result => result.status === 'fulfilled').map(result => result.value);
|
|
3195
|
+
let failed = results.length - threadIds.length;
|
|
3196
|
+
if (failed) {
|
|
3197
|
+
logger.error(
|
|
3198
|
+
Object.assign({ msg: `Some ${label} workers failed to start; they will be respawned` }, logFields, {
|
|
3199
|
+
ready: threadIds.length,
|
|
3200
|
+
failed,
|
|
3201
|
+
errors: results
|
|
3202
|
+
.filter(result => result.status === 'rejected')
|
|
3203
|
+
.map(result => ({
|
|
3204
|
+
message: result.reason && result.reason.message,
|
|
3205
|
+
exitCode: result.reason && result.reason.exitCode,
|
|
3206
|
+
threadId: result.reason && result.reason.threadId
|
|
3207
|
+
}))
|
|
3208
|
+
})
|
|
3209
|
+
);
|
|
3210
|
+
}
|
|
3211
|
+
if (results.length && !threadIds.length) {
|
|
3212
|
+
throw new Error(`No ${label} worker thread could be started`);
|
|
3213
|
+
}
|
|
3214
|
+
return threadIds;
|
|
3215
|
+
};
|
|
3216
|
+
|
|
3178
3217
|
/**
|
|
3179
3218
|
* Main application startup
|
|
3180
3219
|
* @returns {Promise<void>}
|
|
@@ -3271,6 +3310,13 @@ const startApplication = async () => {
|
|
|
3271
3310
|
for (let key of Object.keys(preparedSettings)) {
|
|
3272
3311
|
await settings.set(key, preparedSettings[key]);
|
|
3273
3312
|
}
|
|
3313
|
+
|
|
3314
|
+
// These keys are re-applied on every boot, so a value saved for one of them in the admin
|
|
3315
|
+
// UI reverts at the next restart. The list is recorded for the settings pages
|
|
3316
|
+
// (lib/ui-routes/settings-page.js) to flag those fields as managed by EENGINE_SETTINGS
|
|
3317
|
+
await settings.set('preparedSettingsKeys', Object.keys(preparedSettings));
|
|
3318
|
+
} else {
|
|
3319
|
+
await settings.clear('preparedSettingsKeys');
|
|
3274
3320
|
}
|
|
3275
3321
|
|
|
3276
3322
|
// Initialize required settings
|
|
@@ -3403,13 +3449,20 @@ const startApplication = async () => {
|
|
|
3403
3449
|
try {
|
|
3404
3450
|
let authData = await settings.get('authData');
|
|
3405
3451
|
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
authData.
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3452
|
+
// Written only when the stored hash differs: passwordVersion is what every admin
|
|
3453
|
+
// session and message-browser token is checked against, so rewriting the same hash
|
|
3454
|
+
// on each boot would log every operator out at every restart
|
|
3455
|
+
if (!authData || authData.password !== preparedPassword) {
|
|
3456
|
+
authData = authData || {};
|
|
3457
|
+
authData.user = authData.user || 'admin';
|
|
3458
|
+
authData.password = preparedPassword;
|
|
3459
|
+
authData.passwordVersion = Date.now();
|
|
3460
|
+
|
|
3461
|
+
await settings.set('authData', authData);
|
|
3462
|
+
logger.debug({ msg: 'Password imported' });
|
|
3463
|
+
} else {
|
|
3464
|
+
logger.debug({ msg: 'Password already imported' });
|
|
3465
|
+
}
|
|
3413
3466
|
} catch (err) {
|
|
3414
3467
|
logger.error({ msg: 'Password import failed', err });
|
|
3415
3468
|
}
|
|
@@ -3481,33 +3534,8 @@ const startApplication = async () => {
|
|
|
3481
3534
|
apiPromises.push(spawnWorker('api', workerSpawnOpts('api', i)));
|
|
3482
3535
|
}
|
|
3483
3536
|
|
|
3484
|
-
//
|
|
3485
|
-
|
|
3486
|
-
// worker failed, preserving the original single-worker "no API worker => exit" behavior.
|
|
3487
|
-
let apiResults = await Promise.allSettled(apiPromises);
|
|
3488
|
-
let apiReady = apiResults.filter(result => result.status === 'fulfilled').length;
|
|
3489
|
-
let apiFailed = apiResults.length - apiReady;
|
|
3490
|
-
if (apiFailed) {
|
|
3491
|
-
logger.error({
|
|
3492
|
-
msg: 'Some API workers failed to start; they will be respawned',
|
|
3493
|
-
requested: apiWorkersRequested,
|
|
3494
|
-
attempted: apiResults.length,
|
|
3495
|
-
ready: apiReady,
|
|
3496
|
-
failed: apiFailed,
|
|
3497
|
-
errors: apiResults
|
|
3498
|
-
.filter(result => result.status === 'rejected')
|
|
3499
|
-
.map(result => ({
|
|
3500
|
-
message: result.reason && result.reason.message,
|
|
3501
|
-
exitCode: result.reason && result.reason.exitCode,
|
|
3502
|
-
threadId: result.reason && result.reason.threadId
|
|
3503
|
-
}))
|
|
3504
|
-
});
|
|
3505
|
-
}
|
|
3506
|
-
if (!apiReady) {
|
|
3507
|
-
// No API worker came up at all - fatal, same as the original single-worker behavior. This
|
|
3508
|
-
// rejects startApplication(), which logs fatal and exits the process.
|
|
3509
|
-
throw new Error('No API worker thread could be started');
|
|
3510
|
-
}
|
|
3537
|
+
// `attempted` can be below `requested` after the SO_REUSEPORT fallback above
|
|
3538
|
+
let apiReady = (await settleWorkerFleet('API', apiPromises, { requested: apiWorkersRequested, attempted: apiPromises.length })).length;
|
|
3511
3539
|
logger.info({ msg: 'API workers started', requested: apiWorkersRequested, ready: apiReady });
|
|
3512
3540
|
|
|
3513
3541
|
// Small delay to allow API to start
|
|
@@ -3518,7 +3546,8 @@ const startApplication = async () => {
|
|
|
3518
3546
|
for (let i = 0; i < config.workers.imap; i++) {
|
|
3519
3547
|
workerPromises.push(spawnWorker('imap'));
|
|
3520
3548
|
}
|
|
3521
|
-
|
|
3549
|
+
|
|
3550
|
+
let threadIds = await settleWorkerFleet('IMAP', workerPromises, { requested: config.workers.imap });
|
|
3522
3551
|
logger.info({ msg: 'IMAP workers started', workers: config.workers.imap, threadIds });
|
|
3523
3552
|
|
|
3524
3553
|
// Mark that initial workers are loaded BEFORE assignment
|