Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: return void in InitializeInspector() #44903

Merged
merged 1 commit into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ Environment* CreateEnvironment(
Environment* env = new Environment(
isolate_data, context, args, exec_args, nullptr, flags, thread_id);
#if HAVE_INSPECTOR
// TODO(joyeecheung): handle the exit code returned by InitializeInspector().
if (env->should_create_inspector()) {
if (inspector_parent_handle) {
env->InitializeInspector(
Expand Down
2 changes: 1 addition & 1 deletion src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ class Environment : public MemoryRetainer {
#if HAVE_INSPECTOR
// If the environment is created for a worker, pass parent_handle and
// the ownership if transferred into the Environment.
ExitCode InitializeInspector(
void InitializeInspector(
std::unique_ptr<inspector::ParentInspectorHandle> parent_handle);
#endif

Expand Down
6 changes: 3 additions & 3 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void SignalExit(int signo, siginfo_t* info, void* ucontext) {
#endif // __POSIX__

#if HAVE_INSPECTOR
ExitCode Environment::InitializeInspector(
void Environment::InitializeInspector(
std::unique_ptr<inspector::ParentInspectorHandle> parent_handle) {
std::string inspector_path;
bool is_main = !parent_handle;
Expand All @@ -187,7 +187,7 @@ ExitCode Environment::InitializeInspector(
is_main);
if (options_->debug_options().inspector_enabled &&
!inspector_agent_->IsListening()) {
return ExitCode::kInvalidCommandLineArgument2; // Signal internal error
return;
}

profiler::StartProfilers(this);
Expand All @@ -196,7 +196,7 @@ ExitCode Environment::InitializeInspector(
inspector_agent_->PauseOnNextJavascriptStatement("Break at bootstrap");
}

return ExitCode::kNoFailure;
return;
}
#endif // HAVE_INSPECTOR

Expand Down
4 changes: 0 additions & 4 deletions src/node_main_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ NodeMainInstance::CreateMainEnvironment(ExitCode* exit_code) {
SetIsolateErrorHandlers(isolate_, {});
env->InitializeMainContext(context, &(snapshot_data_->env_info));
#if HAVE_INSPECTOR
// TODO(joyeecheung): handle the exit code returned by
// InitializeInspector().
env->InitializeInspector({});
#endif

Expand All @@ -201,8 +199,6 @@ NodeMainInstance::CreateMainEnvironment(ExitCode* exit_code) {
EnvironmentFlags::kDefaultFlags,
{}));
#if HAVE_INSPECTOR
// TODO(joyeecheung): handle the exit code returned by
// InitializeInspector().
env->InitializeInspector({});
#endif
if (env->principal_realm()->RunBootstrapping().IsEmpty()) {
Expand Down
2 changes: 0 additions & 2 deletions src/node_snapshotable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1173,8 +1173,6 @@ ExitCode SnapshotBuilder::Generate(SnapshotData* out,
// in the future).
if (snapshot_type == SnapshotMetadata::Type::kFullyCustomized) {
#if HAVE_INSPECTOR
// TODO(joyeecheung): handle the exit code returned by
// InitializeInspector().
env->InitializeInspector({});
#endif
if (LoadEnvironment(env, StartExecutionCallback{}).IsEmpty()) {
Expand Down
59 changes: 59 additions & 0 deletions test/parallel/test-inspect-address-in-use.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();

const { spawnSync } = require('child_process');
const { createServer } = require('http');
const assert = require('assert');
const fixtures = require('../common/fixtures');
const entry = fixtures.path('empty.js');
const { Worker } = require('worker_threads');

function testOnServerListen(fn) {
const server = createServer((socket) => {
socket.end('echo');
});

server.on('listening', () => {
fn(server);
server.close();
});
server.listen(0, '127.0.0.1');
}

function testChildProcess(getArgs, exitCode) {
testOnServerListen((server) => {
const { port } = server.address();
const child = spawnSync(process.execPath, getArgs(port));
const stderr = child.stderr.toString().trim();
const stdout = child.stdout.toString().trim();
console.log('[STDERR]');
console.log(stderr);
console.log('[STDOUT]');
console.log(stdout);
const match = stderr.match(
/Starting inspector on 127\.0\.0\.1:(\d+) failed: address already in use/
);
assert.notStrictEqual(match, null);
assert.strictEqual(match[1], port + '');
assert.strictEqual(child.status, exitCode);
});
}

testChildProcess(
(port) => [`--inspect=${port}`, '--build-snapshot', entry], 0);
testChildProcess(
(port) => [`--inspect=${port}`, entry], 0);

testOnServerListen((server) => {
const { port } = server.address();
const worker = new Worker(entry, {
execArgv: [`--inspect=${port}`]
});

worker.on('error', common.mustNotCall());

worker.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
}));
});