Skip to content

Commit 4a96ed4

Browse files
sam-githubaddaleax
authored andcommitted
src: check whether inspector is doing io
Inspector start means that it exists, but doesn't mean it is listening on a port, that only happens if it is doing I/O (i.e. has an io object). PR-URL: #13504 Fixes: #13499 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 1c7f917 commit 4a96ed4

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/node.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -3059,8 +3059,8 @@ static void DebugPortGetter(Local<Name> property,
30593059
#if HAVE_INSPECTOR
30603060
if (port == 0) {
30613061
Environment* env = Environment::GetCurrent(info);
3062-
if (env->inspector_agent()->IsStarted())
3063-
port = env->inspector_agent()->io()->port();
3062+
if (auto io = env->inspector_agent()->io())
3063+
port = io->port();
30643064
}
30653065
#endif // HAVE_INSPECTOR
30663066
info.GetReturnValue().Set(port);

test/inspector/test-inspector-port-zero.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const assert = require('assert');
77
const { URL } = require('url');
88
const { spawn } = require('child_process');
99

10-
function test(arg) {
10+
function test(arg, port = '') {
1111
const args = [arg, '-p', 'process.debugPort'];
1212
const proc = spawn(process.execPath, args);
1313
proc.stdout.setEncoding('utf8');
@@ -18,7 +18,6 @@ function test(arg) {
1818
proc.stderr.on('data', (data) => stderr += data);
1919
proc.stdout.on('close', assert.ifError);
2020
proc.stderr.on('close', assert.ifError);
21-
let port = '';
2221
proc.stderr.on('data', () => {
2322
if (!stderr.includes('\n')) return;
2423
assert(/Debugger listening on (.+)/.test(stderr));
@@ -46,3 +45,9 @@ test('--inspect=localhost:0');
4645
test('--inspect-brk=0');
4746
test('--inspect-brk=127.0.0.1:0');
4847
test('--inspect-brk=localhost:0');
48+
49+
// In these cases, the inspector doesn't listen, so an ephemeral port is not
50+
// allocated and the expected value of `process.debugPort` is `0`.
51+
test('--inspect-port=0', '0');
52+
test('--inspect-port=127.0.0.1:0', '0');
53+
test('--inspect-port=localhost:0', '0');

0 commit comments

Comments
 (0)