From b1eafe14fdacdd05b0eff01d0eeca851add133f9 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 24 Aug 2022 21:52:54 +0800 Subject: [PATCH] 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. PR-URL: https://github.com/nodejs/node/pull/44359 Reviewed-By: Moshe Atlow Reviewed-By: Richard Lau --- lib/internal/debugger/inspect.js | 7 +++++-- test/common/debugger.js | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/internal/debugger/inspect.js b/lib/internal/debugger/inspect.js index 42b5c64ab87029..e006f513f9b93f 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; @@ -64,7 +64,10 @@ async function portIsFree(host, port, timeout = 9999) { 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; 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);