diff options
| author | dakkar <dakkar@thenautilus.net> | 2024-07-21 11:23:49 +0100 |
|---|---|---|
| committer | dakkar <dakkar@thenautilus.net> | 2024-07-21 11:32:39 +0100 |
| commit | 3eff85a3d32c1f4ce4e7960fc1cfc0014a6b8467 (patch) | |
| tree | f0007a40deb750761d94eddbfb064ccaf3da462f /packages/backend/src/boot | |
| parent | merge: Stop banners and backgrounds from being animated when showing animated... (diff) | |
| download | sharkey-3eff85a3d32c1f4ce4e7960fc1cfc0014a6b8467.tar.gz sharkey-3eff85a3d32c1f4ce4e7960fc1cfc0014a6b8467.tar.bz2 sharkey-3eff85a3d32c1f4ce4e7960fc1cfc0014a6b8467.zip | |
error out when we can't spawn workers - fixes #586
Setting `clusterLimit` to 0 means no workers are started, which
usually breaks things. Also, some "hardening" things may prevent node
from seeing how many CPUs the machine has, which has the same effect.
With this commit we provide hopefully-useful error messages.
Diffstat (limited to 'packages/backend/src/boot')
| -rw-r--r-- | packages/backend/src/boot/master.ts | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/packages/backend/src/boot/master.ts b/packages/backend/src/boot/master.ts index 303ba94207..879249e231 100644 --- a/packages/backend/src/boot/master.ts +++ b/packages/backend/src/boot/master.ts @@ -180,7 +180,16 @@ async function connectDb(): Promise<void> { */ async function spawnWorkers(limit = 1) { - const workers = Math.min(limit, os.cpus().length); + 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); + } + bootLogger.info(`Starting ${workers} worker${workers === 1 ? '' : 's'}...`); await Promise.all([...Array(workers)].map(spawnWorker)); bootLogger.succ('All workers started'); |