[Xcb] [PATCH] Handle EAGAIN errno from poll(2) or select(2)

Josh Triplett josh at joshtriplett.org
Thu Aug 20 09:21:59 PDT 2015

On Thu, Aug 20, 2015 at 12:18:41AM -0700, Jeremy Sequoia wrote:
> Yeah, I thought about sleeping before retrying in the EAGAIN case to
> avoid a possible busy loop.  I can do that if you prefer.
> As I indicated in the commit message, there is know known fallout from
> the lack of EAGAIN handling.  There is no behavioral problem.  Indeed
> the only time someone should ever get back EAGAIN from poll or select
> on darwin is under resource pressure, and its likely the user would
> have bigger concerns than this at that point.
> I just happened to notice this while tracing code to figure out why
> someone on stackoverflow was seeing recv() of the DISPLAY socket
> erring out with EAGAIN and then hanging.

If Darwin/OSX returns EAGAIN to a blocking call under *any*
circumstances, including "resource pressure", that's a serious bug.
Don't work around it in XCB or any other library, *especially* because
no other platform should behave the same way.  EAGAIN means "The socket
is marked nonblocking and the receive operation would block, or a
receive timeout had been set and the timeout expired before data was
received."  A blocking call with no timeout should never return EAGAIN;
it should either block or return some fatal error.

Libraries should *definitely* not have to include "wait a bit and try
again" logic; that's the kernel's job.

If you want a way to work around that on Darwin, you could create some
wrapper library around functions like recv that hides the incorrect
behavior.  But first, I'd suggest reporting a bug against Darwin for
violating the spec.

- Josh Triplett

More information about the Xcb mailing list