Inspector session is already connected
Production Risk
Low — inspector Session usage is confined to developer tooling and profiling.
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.
- 1Calling session.connect() more than once on the same Session instance
- 2Reusing a Session instance that was previously connected without disconnecting
Triggered when connect() is called on an inspector.Session that is already in a connected state.
const inspector = require('inspector');
const session = new inspector.Session();
session.connect();
session.connect(); // already connected — throwsexpected output
Error [ERR_INSPECTOR_ALREADY_CONNECTED]: The inspector session is already connected
Fix 1
Disconnect before reconnecting
WHEN When reusing an inspector Session
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
const session2 = new inspector.Session(); session2.connect();
Why this works
A new Session instance starts in the disconnected state and can be connected immediately.
const inspector = require('inspector');
const session = new inspector.Session();
session.connect();
session.connect(); // already connected — throws // this triggers ERR_INSPECTOR_ALREADY_CONNECTEDtry {
// 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
}
}// Validate inputs before calling the operation
function safe_err_inspector_already_connected(...args) {
// validate args here
return performOperation(...args)
}✕ Call connect() on an already-connected Session
Sessions support only one connection at a time; connect() is idempotent only if disconnected first.
Node.js Error Codes Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev