ESTALE
Linux / POSIXERRORNotableFilesystemHIGH confidence

Stale File Handle

Production Risk

Common with NFSv3 after server reboots; implement ESTALE-aware retry logic.

What this means

ESTALE (errno 116) is returned by NFS when a file handle is stale — meaning the file or directory it referred to no longer exists on the NFS server, or the server was rebooted and state was lost.

Why it happens
  1. 1NFS server rebooted — stateful file handles are invalidated
  2. 2File or directory deleted on the server while a client still holds an open fd or path reference
  3. 3NFS server failover that changes file handle mappings
How to reproduce

read() on an NFS file after the server rebooted.

trigger — this will error
trigger — this will error
// File handle valid before server reboot
ssize_t n = read(nfs_fd, buf, sizeof(buf));
// Returns -1, errno = ESTALE after server reboot

expected output

read: Stale file handle (ESTALE)

Fix 1

Close, reopen, and retry the operation

WHEN When ESTALE is returned on an NFS fd

Close, reopen, and retry the operation
if (errno == ESTALE) {
  close(fd);
  // Re-open the file by path
  fd = open(filepath, O_RDWR);
  if (fd >= 0) {
    lseek(fd, offset, SEEK_SET);
    read(fd, buf, sizeof(buf));
  }
}

Why this works

Closing and reopening re-establishes the file handle with the server.

Fix 2

Use NFS v4 with session recovery

WHEN For production NFS deployments

Use NFS v4 with session recovery
# Mount with NFSv4 for better server reboot recovery
mount -t nfs -o vers=4 server:/export /mnt

Why this works

NFSv4 has session-based recovery that reduces ESTALE occurrences after server restarts.

What not to do

Retry the same fd after ESTALE

The file handle is permanently invalidated; the fd must be closed and reopened.

Sources

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

← All Linux / POSIX errors