EPIPE
Linux / POSIXWARNCommonI/OHIGH confidence

Broken Pipe

What this means

A write was attempted to a pipe or socket where the reading end has been closed. By default, SIGPIPE is delivered to the process, which will terminate it unless the signal is handled or ignored.

Why it happens
  1. 1The reader of a pipe exited before consuming all of the writer output.
  2. 2A client disconnected while the server was still writing a response.
  3. 3A shell pipeline like cmd | head consumed only some output before head exited.
  4. 4A network connection was closed by the remote end during transmission.
How to reproduce

Writing to a pipe whose reading end has been closed.

trigger — this will error
trigger — this will error
$ yes | head -1
y
# 'yes' receives SIGPIPE when head exits after reading one line

expected output

# 'yes' is killed by SIGPIPE (exit code 141 = 128 + 13)

Fix

Ignore SIGPIPE and handle EPIPE from write return value

WHEN In server or pipeline code that should not crash on client disconnect

Ignore SIGPIPE and handle EPIPE from write return value
// C: ignore SIGPIPE globally
signal(SIGPIPE, SIG_IGN);

// Then check write return value:
ssize_t n = write(fd, buf, len);
if (n == -1 && errno == EPIPE) {
  // Remote end closed - stop writing
  close(fd);
}

Why this works

Ignoring SIGPIPE prevents the process from crashing. Checking for EPIPE in write() allows graceful cleanup.

Sources
Official documentation ↗

Linux Programmer Manual errno(3)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Linux / POSIX errors