ERR_INSPECTOR_ALREADY_CONNECTED
Node.jsERRORCriticalInspectorHIGH confidence

Inspector session is already connected

Production Risk

Low — inspector Session usage is confined to developer tooling and profiling.

What this means

Thrown when inspector.Session.connect() is called on a session that is already connected. An inspector Session can only have one active connection at a time; calling connect() again without disconnecting first is not allowed.

Why it happens
  1. 1Calling session.connect() more than once on the same Session instance
  2. 2Reusing a Session instance that was previously connected without disconnecting
How to reproduce

Triggered when connect() is called on an inspector.Session that is already in a connected state.

trigger — this will error
trigger — this will error
const inspector = require('inspector');
const session = new inspector.Session();
session.connect();
session.connect(); // already connected — throws

expected output

Error [ERR_INSPECTOR_ALREADY_CONNECTED]: The inspector session is already connected

Fix 1

Disconnect before reconnecting

WHEN When reusing an inspector Session

Disconnect before reconnecting
session.disconnect();
session.connect(); // reconnect cleanly

Why this works

disconnect() releases the current connection, allowing connect() to succeed again.

Fix 2

Create a new Session instance

WHEN When you want a fresh connection

Create a new Session instance
const session2 = new inspector.Session();
session2.connect();

Why this works

A new Session instance starts in the disconnected state and can be connected immediately.

Code examples
Triggerjs
const inspector = require('inspector');
const session = new inspector.Session();
session.connect();
session.connect(); // already connected — throws  // this triggers ERR_INSPECTOR_ALREADY_CONNECTED
Handle in try/catchjs
try {
  // operation that may throw ERR_INSPECTOR_ALREADY_CONNECTED
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_INSPECTOR_ALREADY_CONNECTED') {
    console.error('ERR_INSPECTOR_ALREADY_CONNECTED:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_inspector_already_connected(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Call connect() on an already-connected Session

Sessions support only one connection at a time; connect() is idempotent only if disconnected first.

Sources
Official documentation ↗

Node.js Error Codes Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Node.js errors