summaryrefslogtreecommitdiff
path: root/packages/backend/src/boot
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2024-07-21 13:29:54 +0100
committerdakkar <dakkar@thenautilus.net>2024-07-21 13:29:54 +0100
commitf18f30cb7914b7d8f7123f8e293fe8fc113ed474 (patch)
treec19ed2b94e743332fbafea4c8fa809bf5f352682 /packages/backend/src/boot
parenterror out when we can't spawn workers - fixes #586 (diff)
downloadsharkey-f18f30cb7914b7d8f7123f8e293fe8fc113ed474.tar.gz
sharkey-f18f30cb7914b7d8f7123f8e293fe8fc113ed474.tar.bz2
sharkey-f18f30cb7914b7d8f7123f8e293fe8fc113ed474.zip
ignore cpuCount when it's 0 - fixes #586
seems more useful this way
Diffstat (limited to 'packages/backend/src/boot')
-rw-r--r--packages/backend/src/boot/master.ts15
1 files changed, 7 insertions, 8 deletions
diff --git a/packages/backend/src/boot/master.ts b/packages/backend/src/boot/master.ts
index 879249e231..f757ed64b9 100644
--- a/packages/backend/src/boot/master.ts
+++ b/packages/backend/src/boot/master.ts
@@ -112,6 +112,11 @@ export async function masterMain() {
await server();
}
+ if (config.clusterLimit === 0) {
+ bootLogger.error("Configuration error: we can't create workers, `config.clusterLimit` is 0 (if you don't want to use clustering, set the environment variable `MK_DISABLE_CLUSTERING` to a non-empty value instead)", null, true);
+ process.exit(1);
+ }
+
await spawnWorkers(config.clusterLimit);
}
@@ -181,14 +186,8 @@ async function connectDb(): Promise<void> {
async function spawnWorkers(limit = 1) {
const cpuCount = os.cpus().length;
- const workers = Math.min(limit, cpuCount);
- if (workers === 0) {
- const cause = cpuCount === 0
- ? 'you seem to have no CPUs (this may be caused by some "hardening" system)'
- : "`config.clusterLimit` is 0 (if you don't want to use clustering, set the environment variable `MK_DISABLE_CLUSTERING` to a non-empty value instead)";
- bootLogger.error(`Configuration error: we can't create workers, ${cause}`, null, true);
- process.exit(1);
- }
+ // in some weird environments, node can't count the CPUs; we trust the config in those cases
+ const workers = cpuCount === 0 ? limit : Math.min(limit, cpuCount);
bootLogger.info(`Starting ${workers} worker${workers === 1 ? '' : 's'}...`);
await Promise.all([...Array(workers)].map(spawnWorker));