denoland/deno · error · Error

ERR_INSPECTOR_NOT_CONNECTED

ERR_INSPECTOR_NOT_CONNECTED

Error message

Session is not connected

What it means

Session.post(method, params, callback) dispatches a Chrome DevTools Protocol message. After argument validation (params object, callback function), it checks the private #connection and throws ERR_INSPECTOR_NOT_CONNECTED when there is no live connection — post() ran before connect()/connectToMainThread(), or after disconnect() cleared the connection and pending state.

Source

Thrown at ext/node/polyfills/inspector.js:194

      this.#isDraining = false;
    }
  }

  post(method, params, callback) {
    validateString(method, "method");
    if (!callback && typeof params === "function") {
      callback = params;
      params = null;
    }
    if (params) {
      validateObject(params, "params");
    }
    if (callback) {
      validateFunction(callback, "callback");
    }

    if (!this.#connection) {
      throw new ERR_INSPECTOR_NOT_CONNECTED();
    }
    const id = this.#nextId++;
    const message = { id, method };
    if (params) {
      message.params = params;
    }
    if (callback) {
      this.#messageCallbacks.set(id, callback);
    }
    op_inspector_dispatch(this.#connection, JSONStringify(message));
  }

  disconnect() {
    if (!this.#connection) {
      return;
    }
    op_inspector_disconnect(this.#connection);
    this.#connection = null;

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Call session.connect() (or connectToMainThread() in a worker) immediately after constructing the Session, before the first post().
  2. Route every post through a wrapper that checks your own connected flag, set in connect() and cleared in disconnect().
  3. Cancel or drain pending callbacks before disconnecting so late posts are skipped.

Example fix

// before
const session = new inspector.Session();
session.post('Runtime.enable'); // ERR_INSPECTOR_NOT_CONNECTED

// after
const session = new inspector.Session();
session.connect();
session.post('Runtime.enable');
Defensive patterns

Strategy: validation

Validate before calling

import { Session } from 'node:inspector';
class SafeSession {
  #s = new Session();
  #connected = false;
  connect() { this.#s.connect(); this.#connected = true; }
  disconnect() { this.#s.disconnect(); this.#connected = false; }
  post(method, params, cb) {
    if (!this.#connected) throw new Error('inspector session not connected');
    this.#s.post(method, params, cb);
  }
}

Try / catch

try {
  session.post('Runtime.enable');
} catch (e) {
  if (e.code === 'ERR_INSPECTOR_NOT_CONNECTED') {
    session.connect();
    session.post('Runtime.enable');
  } else throw e;
}

Prevention

When it happens

Trigger: const s = new inspector.Session(); s.post('Runtime.enable'); — no connect() call. Also posting from a timer or callback that fires after you already called disconnect().

Common situations: Copying CDP snippets that omit the connect step; error paths that disconnect early and let queued async code post afterwards; worker scripts that post before connectToMainThread().

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/c082ed2fd1ec1f17. Report an issue: GitHub.