Skip to content

Commit

Permalink
src: check whether inspector is doing io
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
sam-github committed Jun 9, 2017
1 parent 01f4d9a commit c4a61b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3059,8 +3059,8 @@ static void DebugPortGetter(Local<Name> property,
#if HAVE_INSPECTOR
if (port == 0) {
Environment* env = Environment::GetCurrent(info);
if (env->inspector_agent()->IsStarted())
port = env->inspector_agent()->io()->port();
if (auto io = env->inspector_agent()->io())
port = io->port();
}
#endif // HAVE_INSPECTOR
info.GetReturnValue().Set(port);
Expand Down
9 changes: 7 additions & 2 deletions test/inspector/test-inspector-port-zero.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const assert = require('assert');
const { URL } = require('url');
const { spawn } = require('child_process');

function test(arg) {
function test(arg, port = '') {
const args = [arg, '-p', 'process.debugPort'];
const proc = spawn(process.execPath, args);
proc.stdout.setEncoding('utf8');
Expand All @@ -18,7 +18,6 @@ function test(arg) {
proc.stderr.on('data', (data) => stderr += data);
proc.stdout.on('close', assert.ifError);
proc.stderr.on('close', assert.ifError);
let port = '';
proc.stderr.on('data', () => {
if (!stderr.includes('\n')) return;
assert(/Debugger listening on (.+)/.test(stderr));
Expand Down Expand Up @@ -46,3 +45,9 @@ test('--inspect=localhost:0');
test('--inspect-brk=0');
test('--inspect-brk=127.0.0.1:0');
test('--inspect-brk=localhost:0');

// In these cases, the inspector doesn't listen, so an ephemeral port is not
// allocated and the expected value of `process.debugPort` is `0`.
test('--inspect-port=0', '0');
test('--inspect-port=127.0.0.1:0', '0');
test('--inspect-port=localhost:0', '0');

0 comments on commit c4a61b3

Please sign in to comment.