EPIPE (errno 32)

errno 32

LINUX

Broken pipe

Also searched as: Broken pipe, errno 32, EPIPE broken pipe, write EPIPE

Linux terminal running strace with the failing system call and errno highlighted
Linux errno: trace the exact failing system call before changing anything.

What it means

EPIPE, 'Broken pipe' (errno 32), means a program wrote to a pipe or socket whose reading end is already closed. Shell pipelines see it when the next command exits early (for example 'head'), and servers see it when a client disconnects before the response is sent.

Applies to: Linux, macOS (BSD errno), WSL, Docker containers

How to fix EPIPE (errno 32)

  1. In shell pipelines, a broken pipe after 'head' or 'grep -q' is expected and usually harmless
  2. For SSH 'Broken pipe' disconnects, add 'ServerAliveInterval 60' to ~/.ssh/config to keep idle sessions alive
  3. In servers, handle EPIPE as a normal client disconnect: stop writing and close the connection
  4. In Python, catch BrokenPipeError; in Node.js handle 'error' events on streams to avoid crashes
  5. If EPIPE happens on a database or upstream connection, check that side's idle timeouts and enable keep-alives or reconnect logic
  6. If programs die silently, remember SIGPIPE terminates processes by default; ignore it ('signal(SIGPIPE, SIG_IGN)') and check write errors instead

Why it happens

Writing to a pipe or stream socket with no reader generates SIGPIPE and EPIPE. Early-exiting readers, clients that disconnect, timeouts on the remote side and network middleboxes closing idle connections are the usual causes.

FAQ

Why does SSH say 'Broken pipe'?

The connection was idle or the network dropped, and the server or a router closed it. Keep-alive settings in SSH config prevent most cases.

Related errors

Source: Linux kernel errno.h · fixes written and reviewed by the editors (see our editorial policy)

Last updated: