From 2ac729f0f752dd5f6f895aa47b104a3783810dca Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 23 Aug 2022 02:24:48 +0800 Subject: [PATCH 1/3] debugger: decrease timeout used to wait for the port to be free By default, the debugger would query the specified inspector sever port to see if it's available before starting the server, and it would keep retrying until a timeout (previously 9999 ms) is reached. This timeout seems to be longer than necessary. This patch decreases the timeout to 3 seconds. --- lib/internal/debugger/inspect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/debugger/inspect.js b/lib/internal/debugger/inspect.js index 42b5c64ab87029..1dec84ade78f0d 100644 --- a/lib/internal/debugger/inspect.js +++ b/lib/internal/debugger/inspect.js @@ -45,7 +45,7 @@ const debuglog = util.debuglog('inspect'); const { ERR_DEBUGGER_STARTUP_ERROR } = require('internal/errors').codes; -async function portIsFree(host, port, timeout = 9999) { +async function portIsFree(host, port, timeout = 3000) { if (port === 0) return; // Binding to a random port. const retryDelay = 150; From e123a52d5f811e4b290977584b366228b74f8a06 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 23 Aug 2022 19:04:15 +0800 Subject: [PATCH 2/3] debugger: end connections used to check availability of the port The debugger check the availability of the specified inspector server port by trying to connect to it, and retry if the connection can be established (which means the port is not yet free), but it never ends those connections. This patch adds code to end the connections after they are established to avoid taking up more resources than necessary. --- lib/internal/debugger/inspect.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/internal/debugger/inspect.js b/lib/internal/debugger/inspect.js index 1dec84ade78f0d..e006f513f9b93f 100644 --- a/lib/internal/debugger/inspect.js +++ b/lib/internal/debugger/inspect.js @@ -64,7 +64,10 @@ async function portIsFree(host, port, timeout = 3000) { const error = await new Promise((resolve) => { const socket = net.connect(port, host); socket.on('error', resolve); - socket.on('connect', resolve); + socket.on('connect', () => { + socket.end(); + resolve(); + }); }); if (error?.code === 'ECONNREFUSED') { return; From f7b0721c209b1f1a957b96ce85de919bd783d36d Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 24 Aug 2022 16:36:34 +0800 Subject: [PATCH 3/3] test: increase timeout in the debugger tests on Windows On certain Windows machines it may take longer for the testing processes to receive outputs from the debugger process. Increasing the timeout to 15 seconds to avoid failing the tests in those cases. --- test/common/debugger.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/common/debugger.js b/test/common/debugger.js index d2ac4f3b6c5fbf..4aff5b9a0f74d9 100644 --- a/test/common/debugger.js +++ b/test/common/debugger.js @@ -7,7 +7,13 @@ const BREAK_MESSAGE = new RegExp('(?:' + [ 'exception', 'other', 'promiseRejection', ].join('|') + ') in', 'i'); -const TIMEOUT = common.platformTimeout(5000); +let TIMEOUT = common.platformTimeout(5000); +if (common.isWindows) { + // Some of the windows machines in the CI need more time to receive + // the outputs from the client. + // https://github.com/nodejs/build/issues/3014 + TIMEOUT = common.platformTimeout(15000); +} function isPreBreak(output) { return /Break on start/.test(output) && /1 \(function \(exports/.test(output);