[zeromq-dev] Even more fun with accept

Dhammika Pathirana dhammika at gmail.com
Thu Apr 30 07:38:52 CEST 2009


On EMFILE we can temporarily suspend listen socket from poller.
Optionally we may want to keep an atomic counter for active sockets,
and make fd limit configurable with setrlimit.

Set SO_LINGER timeout on accepted sockets to recover closed sockets
without waiting in CLOSED_WAIT state.
Set listen backlog to 1 so that clients will get ECONNREFUSED without
hanging in connect.

ENFILE is more intricate though, I think the best option here is just
to wait few microseconds and retry.
We can also use edge triggered polling on supported platforms, but
that's way more complicated.


On Wed, Apr 29, 2009 at 9:27 AM, Martin Sustrik <sustrik at fastmq.com> wrote:
> Hi,
> I was just told that when EMFILE or ENFILE error (the socket limit is
> exceeded) is returned from accept the connection isn't purged from the
> listening queue.
> The consequence is that polling on the listening socket signalises that
> there's a pending connection, however, there's no way to accept it unless
> some sockets are closed in the meantime.
> Such behaviour results in a busy loop desperately trying to accept the
> connection, ultimately getting the CPU load to 100%.
> Any tips how to solve the problem?
> Martin

More information about the zeromq-dev mailing list