Skip to content
Latchkey

Node "Error: write EPIPE" in CI - Handle the Broken Pipe

EPIPE means your process wrote to a pipe whose reader has gone away. In CI it often happens when stdout is piped to a command that exits early, like head.

What this error means

A node process throws Error: write EPIPE, frequently from process.stdout, when the reader of a pipe closes before all output is written.

node
Error: write EPIPE
    at afterWriteDispatched (node:internal/stream_base_commons:160:15)
    at writeGeneric (node:internal/stream_base_commons:151:3) {
  errno: -32, code: 'EPIPE', syscall: 'write'
}

Common causes

A downstream reader closed the pipe early

Piping node output into a command like head that exits after a few lines closes the read end, so further writes hit EPIPE.

Writing to a socket the peer already closed

The remote end disconnected, and a continued write to that stream raises EPIPE.

How to fix it

Handle the stream error

  1. Attach an error listener to the writable stream.
  2. Exit cleanly on EPIPE instead of letting it become an uncaught exception.
JavaScript
process.stdout.on('error', (err) => {
  if (err.code === 'EPIPE') process.exit(0);
});

Avoid truncating pipes in CI

  1. Remove pipes that close early (head, less) from CI commands.
  2. Write full output to a file or let it complete.

How to prevent it

  • Attach error handlers to long-lived writable streams, avoid piping CI output through early-exiting readers, and treat EPIPE as a normal shutdown condition.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →