4 ms·
There are two ways to avoid getting TIME_WAIT states in the first place: 1. Convince the client to close the connection. The initiator of the close will be th
by ivank 16y ago
There are two ways to avoid getting TIME_WAIT states in the first place:
1. Convince the client to close the connection. The initiator of the close will be the one holding the TIME_WAIT socket (for ~2 minutes)
2. Send RSTs to clients that refuse to close. RST avoids creating a TIME_WAIT state. I think this is slightly more dangerous than a normal FIN close, because wandering duplicates could interfere with the next connection. From Python, you can close a TCP socket in a way that causes a RST to be sent:
# Set SO_LINGER to 1,0 which, by convention, causes a
# connection reset to be sent when close is called,
# instead of the standard FIN shutdown sequence.
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
struct.pack("ii", 1, 0))
(From the patches and branch in http://twistedmatrix.com/trac/ticket/78 http://twistedmatrix.com/trac/ticket/78)