Skip to content

Commit

Permalink
debugger: decrease timeout used to wait for the port to be free
Browse files Browse the repository at this point in the history
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: nodejs/node#44359
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Richard Lau <rlau@redhat.com>
  • Loading branch information
joyeecheung authored and guangwong committed Jan 3, 2023
1 parent 9a906dd commit e95069b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/internal/debugger/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion test/common/debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e95069b

Please sign in to comment.