From 02a5dafdbb823f38f811db538ea3d1db2d442238 Mon Sep 17 00:00:00 2001 From: Minwoo Jung Date: Mon, 14 Jan 2019 23:02:48 +0900 Subject: [PATCH] os: add fallback for undefined CPUs For an unsupported OS, a call to os.cpus() throws an error within os.cpus() itself where it tries to get the length of it. This fixes the issue by adding fallback for undefined CPUs. Fixes: https://github.com/nodejs/node/issues/25483 PR-URL: https://github.com/nodejs/node/pull/25493 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Ruben Bridgewater --- lib/os.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/os.js b/lib/os.js index cc86010f7d0ffb..9886e2c3158bc8 100644 --- a/lib/os.js +++ b/lib/os.js @@ -86,7 +86,8 @@ function loadavg() { } function cpus() { - const data = getCPUs(); + // [] is a bugfix for a regression introduced in 51cea61 + const data = getCPUs() || []; const result = []; for (var i = 0; i < data.length; i += 7) { result.push({