ERR_INSPECTOR_CLOSED
Node.jsERRORCriticalInspectorHIGH confidence

Inspector session was closed

Production Risk

Low — inspector sessions are for development/profiling only.

What this means

Thrown when a method is called on an inspector.Session that has already been closed or disconnected. Once a session is disconnected, its methods (such as post()) can no longer be used.

Why it happens
  1. 1Calling session.post() after session.disconnect() has been called
  2. 2Async callback that uses the session after it has been closed
How to reproduce

Triggered when any Session method is called after the session has been closed.

trigger — this will error
trigger — this will error
const inspector = require('inspector');
const session = new inspector.Session();
session.connect();
session.disconnect();
session.post('Runtime.enable'); // session is closed — throws

expected output

Error [ERR_INSPECTOR_CLOSED]: Session was closed

Fix

Stop using the session after disconnecting

WHEN In async code that may outlive the session

Stop using the session after disconnecting
let connected = true;
session.on('inspectorNotification', (msg) => { /* handle */ });
session.connect();

function cleanUp() {
  connected = false;
  session.disconnect();
}

function sendCommand(method, params) {
  if (!connected) return;
  session.post(method, params);
}

Why this works

A connected flag prevents post() calls after disconnect().

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

Send inspector commands after disconnecting the session

A closed session has no active channel; commands cannot be delivered.

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