mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
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: https://github.com/nodejs/node/pull/13504 Fixes: https://github.com/nodejs/node/issues/13499 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
01f4d9af5e
commit
c4a61b3ee5
@ -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);
|
||||
|
@ -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');
|
||||
@ -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));
|
||||
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user