Reputation: 8030
I was reading the following answer about "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.
It has been pointed out that 'A socket is a 5 tuple (proto, local addr, local port, remote addr, remote port). SO_REUSEADDR just says that you can reuse local addresses. The 5 tuple still must be unique!' by Michael Hunter ([email protected]). This is true, and this is why it is very unlikely that unexpected data will ever be seen by your server. The danger is that such a 5 tuple is still floating around on the net, and while it is bouncing around, a new connection from the same client, on the same system, happens to get the same remote port. This is explained by Richard Stevens in #2.7 'Please explain the TIME_WAIT state'.
I just can't get the last lines The danger is....TIME_WAIT state.
It says if there is still a same floating tuple on the net then....but what if is there the same tuple 1 hour later? I can't understand, can someone explain it?
Upvotes: 4
Views: 1511
Reputation: 310850
It's a poorly expressed answer. Link please so I can comment.
The danger is that a packet with the old 5-tuple is still in transit in the network. If it arrives after the new connection is created, it risks being seen as intended for that connection, and so delivered to that connection, which would violate TCP's integrity guarantee.
What if there is the same tuple 1 hour later?
There can't be. IP packets have a Maximum Segment Lifetime (MSL) of a minute. The TIME_WAIT state persists for 2*MSL. That's how it works.
Upvotes: 5