[erlang-questions] HTTP requests and the meaning of eaddrinuse

Johnny Billquist bqt@REDACTED
Fri Jan 30 16:00:08 CET 2009


Sverker Eriksson wrote:
> Johnny Billquist wrote:
>> [...] you will most probably hit the limit of the number of open file 
>> descriptors long before you exhaust all the local port numbers. By 
>> default on on my mac, the max file descriptors is 256 (per process). 
>> There is also a limit on the total number of file descriptors in the OS. 
>> Nowhere near the theoretical limit of 65536 ports in tcp. So that should 
>> give you enfile or emfile.
>>
>>   
> 
> The internal TIME_WAIT state of the TCP protocol may cause exhaustion of 
> port numbers even though the file descriptor limit is much lower than 
> 65536. Use the netstat command tool to view lingering connections in 
> TIME_WAIT state.

True, if the connections aren't closed properly. But yes, that could be 
it. I wonder if eaddrinuse really is returned in that case. TCP should 
still not even select a port that is already in use. But there aren't 
any explicit error code for telling that there are no "free" port numbers.
Also, tcp will not grab any random port when requested to allocate one. 
In fact, on MAC OSX, for instance, this is controlled by
net.inet.ip.portrange.hilast: 65535
net.inet.ip.portrange.hifirst: 49152

which gives you a range of "only" 16384 ports, from which a port number 
is allocated.

	Johnny

-- 
Johnny Billquist                  || "I'm on a bus
                                   ||  on a psychedelic trip
email: bqt@REDACTED             ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol



More information about the erlang-questions mailing list