ESPIPE
Linux / POSIXERRORNotableI/OHIGH confidence

Illegal Seek

Production Risk

Low — usually indicates a code path that incorrectly assumes regular file semantics for a piped input.

What this means

ESPIPE (errno 29) is returned when lseek() or a seek-related operation is called on a file descriptor that does not support seeking — specifically pipes, FIFOs, and sockets, which are sequential-only.

Why it happens
  1. 1Calling lseek() on a pipe or FIFO
  2. 2Calling lseek() on a socket file descriptor
  3. 3A library function internally calls lseek() on a descriptor backed by a pipe
How to reproduce

Seeking on a pipe file descriptor.

trigger — this will error
trigger — this will error
// C: seek on a pipe
int pipefd[2];
pipe(pipefd);
lseek(pipefd[0], 0, SEEK_SET);
// Returns -1, errno = ESPIPE

expected output

lseek: Illegal seek (ESPIPE)

Fix

Check whether the descriptor supports seeking before calling lseek

WHEN When the fd type is unknown at compile time

Check whether the descriptor supports seeking before calling lseek
// C: test if seekable
off_t pos = lseek(fd, 0, SEEK_CUR);
if (pos == -1 && errno == ESPIPE) {
    // fd is a pipe/socket — sequential only
}

Why this works

lseek(fd, 0, SEEK_CUR) with ESPIPE result reliably detects non-seekable fds. Adjust code to avoid seek-dependent logic on such descriptors.

Sources
Official documentation ↗

Linux Programmer Manual lseek(2)

pipe(2)

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

← All Linux / POSIX errors