Skip to content
Browse files
inspector: expose inspector.close on workers
Workers can open their own inspector agent with ``.
They should be able to close their own inspector agent too with

PR-URL: #44489
Reviewed-By: Moshe Atlow <>
Reviewed-By: Anna Henningsen <>
  • Loading branch information
legendecas authored and RafaelGSS committed Sep 26, 2022
1 parent 7db2974 commit 1b160517f57cc960e3974efb8699e044abc7d082
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
@@ -19,8 +19,6 @@ const inspector = require('node:inspector');

Deactivate the inspector. Blocks until there are no active connections.

This function is not available in [worker threads][].

## `inspector.console`

* {Object} An object to send messages to the remote inspector console.
@@ -262,4 +260,3 @@'HeapProfiler.takeHeapSnapshot', null, (err, r) => {
[`session.connect()`]: #sessionconnect
[security warning]:
[worker threads]:
@@ -32,6 +32,7 @@ const {
} = require('internal/validators');
const { isMainThread } = require('worker_threads');
const { _debugEnd } = internalBinding('process_methods');

const {
@@ -195,7 +196,7 @@ function inspectorWaitForDebugger() {

module.exports = {
open: inspectorOpen,
close: process._debugEnd,
close: _debugEnd,
waitForDebugger: inspectorWaitForDebugger,
@@ -562,24 +562,24 @@ static void Initialize(Local<Object> target,
// define various internal methods
if (env->owns_process_state()) {
SetMethod(context, target, "_debugProcess", DebugProcess);
SetMethod(context, target, "_debugEnd", DebugEnd);
SetMethod(context, target, "abort", Abort);
SetMethod(context, target, "causeSegfault", CauseSegfault);
SetMethod(context, target, "chdir", Chdir);

SetMethod(context, target, "umask", Umask);
SetMethod(context, target, "_rawDebug", RawDebug);
SetMethod(context, target, "memoryUsage", MemoryUsage);
SetMethod(context, target, "rss", Rss);
SetMethod(context, target, "cpuUsage", CPUUsage);
SetMethod(context, target, "resourceUsage", ResourceUsage);

SetMethod(context, target, "_debugEnd", DebugEnd);
SetMethod(context, target, "_getActiveRequestsInfo", GetActiveRequestsInfo);
SetMethod(context, target, "_getActiveRequests", GetActiveRequests);
SetMethod(context, target, "_getActiveHandles", GetActiveHandles);
SetMethod(context, target, "_getActiveHandlesInfo", GetActiveHandlesInfo);
SetMethod(context, target, "_kill", Kill);
SetMethod(context, target, "_rawDebug", RawDebug);

SetMethodNoSideEffect(context, target, "cwd", Cwd);
SetMethod(context, target, "dlopen", binding::DLOpen);
@@ -0,0 +1,34 @@
'use strict';

const common = require('../common');
const { isMainThread, Worker } = require('worker_threads');
const assert = require('assert');
const inspector = require('inspector');

if (!isMainThread) {
// Verify the inspector api on the worker thread.
assert.strictEqual(inspector.url(), undefined);, undefined, false);
const wsUrl = inspector.url();
assert.strictEqual(inspector.url(), undefined);

// Open inspector on the main thread first., undefined, false);
const wsUrl = inspector.url();

const worker = new Worker(__filename);
worker.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);

// Verify inspector on the main thread is still active.
assert.strictEqual(inspector.url(), wsUrl);
assert.strictEqual(inspector.url(), undefined);

0 comments on commit 1b16051

Please sign in to comment.