Skip to content

Commit 4b03662

Browse files
Work around os.cpus() returning an empty array on unsupported platforms
`os.cpus()` can return empty arrays on platforms not officially supported by Node.js. Use 1 as a minimum. See <nodejs/node#38190>. Co-authored-by: Mark Wubben <[email protected]>
1 parent 02f626f commit 4b03662

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/api.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,16 @@ export default class Api extends Emittery {
246246
}
247247
}));
248248

249-
// Resolve the correct concurrency value.
250-
let concurrency = Math.min(os.cpus().length, isCi ? 2 : Number.POSITIVE_INFINITY);
251-
if (apiOptions.concurrency > 0) {
252-
concurrency = apiOptions.concurrency;
253-
}
254-
249+
// Resolve the correct concurrency value. Note that `os.cpus()` can return empty arrays on
250+
// platforms not officially supported by Node.js. Use 1 as a minimum.
251+
// See <https://github.com/nodejs/node/issues/38190>.
252+
let concurrency = Math.max(1, os.cpus().length);
255253
if (apiOptions.serial) {
256254
concurrency = 1;
255+
} else if (apiOptions.concurrency > 0) {
256+
concurrency = apiOptions.concurrency;
257+
} else if (isCi) {
258+
concurrency = 2;
257259
}
258260

259261
const deregisteredSharedWorkers = [];

0 commit comments

Comments
 (0)