go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Another way to fix TIME_WAIT
 
Subject: Another way to fix TIME_WAIT
Author: EricJ
In response to: How to Fix It?
Posted on: 02/23/2010 09:12:16 PM

What's behind the scene?

RFC 793 TIME-WAIT - represents waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request.

RFC 793 sets the TIME-OUT to be twice the Maximum Segment Lifetime, or 2MSL. Since MSL, the maximum time a packet can wonder around Internet, is set to 2 minutes, 2MSL is 4 minutes. Since there is no ACK to an ACK, the active closer can't do anything but to wait 4 minutes if it adheres to the TCP/IP protocol correctly, just in case the passive sender has not received the ACK to its FIN (theoretically).


Another way to fix TIME_WAIT

The workaround solution is to ignore the TIME_WAIT by using SO_REUSEADDR option.

[JAVA DOC]:

setReuseAddress(boolean on) throws SocketException

Enable/disable the SO_REUSEADDR socket option. 

When a TCP connection is closed the connection may remain in a timeout state 
for a period of time after the connection is closed (typically known as the
TIME_WAIT state or 2MSL wait state). For applications using a well known socket
address or port it may not be possible to bind a socket to the required
SocketAddress if there is a connection in the timeout state involving the socket
address or port. 

Enabling SO_REUSEADDR prior to binding the socket using bind(SocketAddress) 
allows the socket to be bound even though a previous connection is in a timeout state. 


What exactly does SO_REUSEADDR do?

This socket option tells the kernel that even if this port is busy (in
the TIME_WAIT state), go ahead and reuse it anyway. If it is busy,
but with another state, you will still get an address already in use
error. It is useful if your server has been shut down, and then
restarted right away while sockets are still active on its port. You
should be aware that if any unexpected data comes in, it may confuse
your server, but while this is possible, it is not likely.



 

> On 04/12/2007 09:37:52 PM EricJ wrote:

The TCP/IP layer has a default maximum connections allowed in the TIMED_WAIT state. To remedy this, modify or create the following registry keys:

  • TcpTimedWaitDelay, sets TIME_WAIT parameter to 30 seconds, default is 240.
  • MaxUserPort, sets maximum open ports to 65534, default is 5000





    References:

  •  


     
    Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
     
    Get your own forum today. It's easy and free.