From affecd823c57db3ccb77be7e959f3db8a0662f78 Mon Sep 17 00:00:00 2001 From: Yousif Ahmed Date: Fri, 25 Nov 2022 11:16:02 +0000 Subject: [PATCH] fall back to environment variables if os.hostname fails --- lib/fingerprint.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/fingerprint.js b/lib/fingerprint.js index 41ce488b..e467b564 100644 --- a/lib/fingerprint.js +++ b/lib/fingerprint.js @@ -5,7 +5,16 @@ function getHostname () { try { return os.hostname(); } catch (e) { - return ''; + /** + * This is most likely Windows 7 which is known to cause os.hostname() to break + * @see https://github.com/nodejs/node/issues/41297 + * @see https://github.com/libuv/libuv/issues/3260 + * + * Fallback to take hostname from environment variables + * @see https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/hostname#notes + */ + // eslint-disable-next-line no-underscore-dangle + return process.env._CLUSTER_NETWORK_NAME_ || process.env.COMPUTERNAME || 'hostname'; } }