Why does recvfrom() call return EAGAIN error?

Solution Verified - Updated -


Red Hat Enterprise Linux, all versions


  • The recvfrom() call returns EAGAIN error


This is normal and expected, in the worst case this may indicate an issue with your application.

Root Cause

When recvfrom is used on a non-blocking socket, it returns EAGAIN error if there are no pending data to be read.

As mentioned in man 3 recvfrom:

       The recvfrom() function shall fail if:
              The socket's file descriptor is marked O_NONBLOCK and no data is
              waiting  to  be  received;  or MSG_OOB is set and no out-of-band
              data is available and either the  socket's  file  descriptor  is
              marked  O_NONBLOCK  or  the  socket does not support blocking to
              await out-of-band data.

In case an application has opened non-blocking socket and there are no data on that socket to be read, the recvfrom() call will return EAGAIN error, as described.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.