{"record":{"id":"56dd48510bc98803","repo":"denoland/deno","slug":"err-inspector-already-activated","errorCode":"ERR_INSPECTOR_ALREADY_ACTIVATED","errorMessage":"Inspector is already activated. Close it with inspector.close() before activating it again.","messagePattern":"Inspector is already activated\\. Close it with inspector\\.close\\(\\) before activating it again\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/inspector.js","lineNumber":228,"sourceCode":"    }\n    op_inspector_disconnect(this.#connection);\n    this.#connection = null;\n    for (\n      const { 1: callback } of new SafeMapIterator(this.#messageCallbacks)\n    ) {\n      lazyProcess().default.nextTick(callback, new ERR_INSPECTOR_CLOSED());\n    }\n    this.#messageCallbacks.clear();\n    this.#nextId = 1;\n    this.#pendingMessages.length = 0;\n    this.#drainScheduled = false;\n    this.#isDraining = false;\n  }\n}\n\nfunction open(port, host, wait) {\n  if (op_inspector_enabled()) {\n    throw new ERR_INSPECTOR_ALREADY_ACTIVATED();\n  }\n  // inspectorOpen() currently does not typecheck its arguments and adding\n  // such checks would be a potentially breaking change. However, the native\n  // open() function requires the port to fit into a 16-bit unsigned integer,\n  // causing an integer overflow otherwise, so we at least need to prevent that.\n  if (isUint32(port)) {\n    validateInt32(port, \"port\", 0, 65535);\n  } else {\n    // equiv of handling args[0]->IsUint32()\n    port = undefined;\n  }\n  if (typeof host !== \"string\") {\n    // equiv of handling args[1]->IsString()\n    host = undefined;\n  }\n\n  if (host && !isLoopback(host)) {\n    lazyProcess().default.emitWarning(","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/inspector.js#L210-L246","documentation":"inspector.open([port[, host[, wait]]]) activates the inspector for the process. If an inspector is already active — the process was started with --inspect/--inspect-brk, or inspector.open() was called earlier and not closed — op_inspector_enabled() returns true and open() throws ERR_INSPECTOR_ALREADY_ACTIVATED, with the message telling you to close it via inspector.close() first.","triggerScenarios":"Running `deno run --inspect app.ts` (or equivalent flags) where app.ts itself calls inspector.open(); calling inspector.open() twice, e.g. at startup and again on config reload/SIGHUP.","commonSituations":"Dev scripts that open the inspector programmatically while the launch command already has --inspect; watch/reload loops re-running init code; porting Node debugging recipes that combine both.","solutions":["Guard the call: only open when inspector.url() === undefined (url() returns undefined when no inspector is active).","Call inspector.close() before inspector.open() when re-activating after a previous open.","Drop the --inspect/--inspect-brk flag from the launch command if the program opens the inspector itself."],"exampleFix":"// before - launched with: deno run --inspect app.ts\ninspector.open(9229, '127.0.0.1'); // ERR_INSPECTOR_ALREADY_ACTIVATED\n\n// after\nif (inspector.url() === undefined) {\n  inspector.open(9229, '127.0.0.1');\n}","handlingStrategy":"validation","validationCode":"import inspector from 'node:inspector';\nfunction openInspector(port, host) {\n  if (inspector.url() !== undefined) return inspector.url(); // already active\n  inspector.open(port, host);\n  return inspector.url();\n}","typeGuard":"import inspector from 'node:inspector';\nfunction inspectorIsActive() {\n  return inspector.url() !== undefined;\n}","tryCatchPattern":"try {\n  inspector.open(9229, '127.0.0.1');\n} catch (e) {\n  if (e.code === 'ERR_INSPECTOR_ALREADY_ACTIVATED') {\n    // inspector already running (e.g. via --inspect); continue with inspector.url()\n  } else throw e;\n}","preventionTips":["Never combine --inspect in the launch command with inspector.open() in code.","Make programmatic open() idempotent: check inspector.url() first, or close() before open() in reload paths."],"tags":["inspector","debugging","startup","node-compat"],"backgroundTag":"inspector-already-active","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}