Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4a96ed4

Browse filesBrowse 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 <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 1c7f917 commit 4a96ed4
Copy full SHA for 4a96ed4

File tree

Expand file treeCollapse file tree

2 files changed

+9
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-4
lines changed
Open diff view settings
Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+2-2Lines changed: 2 additions & 2 deletions
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);
Collapse file

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

Copy file name to clipboardExpand all lines: test/inspector/test-inspector-port-zero.js
+7-2Lines changed: 7 additions & 2 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.