ERR_CHILD_CLOSED_BEFORE_REPLY
Node.jsERRORNotableChild ProcessHIGH confidence

Child process closed before sending a reply

Production Risk

Can stall cluster master/worker coordination; always reply to IPC messages before exiting.

What this means

Thrown when a child process that was expected to send a reply via IPC closes its IPC channel before doing so. This typically happens when child_process internals are waiting for a response (e.g. from cluster workers) and the child exits unexpectedly.

Why it happens
  1. 1Child process crashes or exits before sending a required IPC reply
  2. 2Child process calls process.exit() inside a message handler before responding
  3. 3Network or OS-level process termination interrupts IPC communication
How to reproduce

Triggered when the Node.js cluster or child_process internals detect IPC closure before receiving an expected reply.

trigger — this will error
trigger — this will error
// In a cluster worker:
process.on('message', (msg) => {
  if (msg.cmd === 'handshake') {
    process.exit(0); // exits without replying — causes ERR_CHILD_CLOSED_BEFORE_REPLY
  }
});

expected output

Error [ERR_CHILD_CLOSED_BEFORE_REPLY]: Child closed before reply received

Fix

Ensure workers always reply before exiting

WHEN In cluster workers that handle IPC messages

Ensure workers always reply before exiting
process.on('message', (msg) => {
  if (msg.cmd === 'handshake') {
    process.send({ cmd: 'handshake_ack' }); // reply first
    process.exit(0);
  }
});

Why this works

Sending the reply before exiting ensures the parent receives the expected response.

Code examples
Triggerjs
// In a cluster worker:
process.on('message', (msg) => {
  if (msg.cmd === 'handshake') {
    process.exit(0); // exits without replying — causes ERR_CHILD_CLOSED_BEFORE_REPLY
  }
});  // this triggers ERR_CHILD_CLOSED_BEFORE_REPLY
Handle in try/catchjs
try {
  // operation that may throw ERR_CHILD_CLOSED_BEFORE_REPLY
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_CHILD_CLOSED_BEFORE_REPLY') {
    console.error('ERR_CHILD_CLOSED_BEFORE_REPLY:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_child_closed_before_reply(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Call process.exit() inside message handlers before replying

The IPC channel closes on exit; pending replies are never delivered.

Same error in other languages
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