Linux EAGAIN (errno 7) — Resource Temporarily Unavailable

EAGAIN (errno 7) means the resource requested is temporarily unavailable and the operation should be retried later. This error commonly occurs with non-blocking I/O when no data is available for reading, or when a system resource limit has been reached. It is distinct from EWOULDBLOCK because EAGAIN typically implies the caller should retry, while EWOULDBLOCK emphasizes the operation would block.

Common Causes

  • A non-blocking socket has no data available to read
  • Process has hit a file descriptor or memory limit
  • A resource (such as a semaphore or shared memory segment) is temporarily exhausted
  • The system is under heavy load and cannot allocate more resources

How to Fix EAGAIN

1. Retry the Operation

The simplest approach is to retry after a short delay:

# Sleep briefly and retry
sleep 1 && <your_command>

2. Increase File Descriptor Limits

Check and raise the open files limit:

ulimit -n
ulimit -n 65535

3. Adjust System-Wide Resource Limits

Edit /etc/sysctl.conf to tune kernel parameters:

sudo sysctl -w net.core.somaxconn=1024
sudo sysctl -w fs.file-max=2097152

4. Check Process Memory Usage

Monitor resource consumption to identify exhaustion:

free -h
top -o %MEM

Verification

After adjusting limits, verify the change took effect:

ulimit -n
sysctl net.core.somaxconn

Comments