[erlang-questions] eaddrinuse on connect ?
Tomas Abrahamsson
tomas.abrahamsson@REDACTED
Tue Dec 12 18:16:01 CET 2006
>> Hello,
>>
>> When a lot, of outgoing connections are open, I can sometimes see
>> eaddrinuse error on outgoing TCP connect.
>> As the error is obvious for binding/listening to a local socket, I was
>> wondering why this error could occur and how to avoid it.
>
> i think that, for TCP, you need a socket on the sending computer, too.
> for ack/nack, flow control, etc.
Yes, that's true. Each TCP/IP connection can be defined
as a tuple {LocalIP, LocalPort, RemoteIP, RemotePort},
and I think what may be happening is that you're
running out of TCP/IP port numbers (for LocalPort).
These are 16 bits.
>> Can using the reuseaddr parameter help in this situation ?
>
> yes, it should allow you to open the outgoing socket. perhaps you would
> get into trouble if the previous remote computer is still sending things
> back to your local/sending computer. but the sequence number should
> protect you from that... i think it will be ok.
I've never tried the reuseaddr on sockets for outgoing
connects, but here are a couple more ideas, which may
or may not be suitable for you, depending on your setup:
* Set up more IP-numbers on the box and bind to them
when connecting (ie: set the ip option to
gen_tcp:connect/3,4)
(This increases the range of available {LocalIP,LocalPort}
addresses)
* Decrease the time for the TIME_WAIT and/or CLOSE_WAIT
states. Here are some examples of how to set it to 30 seconds:
Solaris: /usr/sbin/ndd -set /dev/tcp tcp_time_wait_interval 30000
Linux: /sbin/sysctl -w net.ipv4.tcp_fin_timeout=30
(This will cause closed connections to return to the
pool of available addresses faster, and can be used
e.g. in lab setups where you know you have a fast
network and there will never be any very late packets)
* Use more machines for setting up connections
(This reduces the range of {LocalIP,LocalPort} being
used on each machine)
BRs
Tomas
More information about the erlang-questions
mailing list