mirror of
https://git.boykissers.com/pawkey/pawkey-sk.git
synced 2025-12-20 04:04:16 +00: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:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user