[zeromq-dev] Even more fun with accept

Martin Sustrik sustrik at fastmq.com
Thu Apr 30 15:17:49 CEST 2009


Holger Hoffstätte wrote:
> Martin Sustrik wrote:
>>> Second, Unix has an interesting strategy for dealing with closed
>>> sockets, namely to keep them around for a minute or so.
>> No way to get around this, I suppose? Some kind of kill -9 for sockets?
> 
> As Pieter said it depends on whether there is still in-flight data or not.
> Also it's different for client and server. So have fun finding all the
> relevant combinations for SO_LINGER and (on Linux) the usefulness of
> net.ipv4.tcp_tw_recycle or net.ipv4.tcp_tw_reuse (for influencing the
> TIME_WAIT state). Or whether they work correctly on any given kernel.
> 
> good luck :)

Trying to tame different SO_LINGER semantics on different platforms 
seems to be a way to hell. A more generic algorithm is needed. What 
about this one:

1. Client cannot connect because of ENFILE/EMFILE. Either fail or wait 
for a while and retry.

2. Server cannot accept because of ENFILE/EMFILE
    a. close the listening socket to kill the connections in the backlog
    b. reopen and rebind the listening socket
    c. if listening socket cannot be reopened because someone stole the 
fd in the meantime, wait for a while and retry

Martin



More information about the zeromq-dev mailing list