mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-15 05:05:42 +01:00
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.
This commit is contained in:
parent
69bdbf22b3
commit
3eff85a3d3
1 changed files with 10 additions and 1 deletions
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue