From 3bd8e4b6a35aa3347d9442b45947e232e1a97fd4 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 422ba6d0c2133b..24c9eab90d6e9e 100644 --- a/lib/os.js +++ b/lib/os.js @@ -89,7 +89,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({