ERR_INVALID_HANDLE_TYPE
Node.jsERRORCommonProcess

Invalid handle type passed to child_process.send()

Quick Answer

Only pass net.Socket, net.Server, dgram.Socket, or process as the handle argument to child_process.send().

Production Risk

Programming error — occurs when incorrect objects are passed as IPC handles.

What this means

Thrown when child_process.send() is called with a handle that is not a supported type. Only net.Socket, net.Server, dgram.Socket, and process objects can be sent as handles over IPC.

Why it happens
  1. 1Passing a plain object, Buffer, or unsupported handle type to process.send(handle)
  2. 2Attempting to pass a file descriptor that was not wrapped in a net.Socket
  3. 3Using child.send() with an HTTP IncomingMessage (not a socket)

Fix

Pass the underlying socket, not the HTTP request

WHEN When sharing connections from an HTTP server with a child process

Pass the underlying socket, not the HTTP request
const http = require('http');
const cp = require('child_process');
const child = cp.fork('./worker.js');

const server = http.createServer((req, res) => {
  // ✓ Send the underlying socket (net.Socket), not req or res
  child.send('socket', req.socket);
});

Why this works

HTTP IncomingMessage wraps a net.Socket but is not itself a transferable handle. Access req.socket to get the underlying socket object.

What not to do

Pass an HTTP request or response object as the handle to child.send()

Only the underlying net.Socket is transferable; the request/response objects are higher-level wrappers that cannot be serialised across the IPC channel.

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