-2

I'm trying to understand, why a socket in state TIME_WAIT prevents binding a listener to address:port combination. It is well known, that a "connection" is identified by 5 elements: protocol, remote address, remote port, local address and local port. TIME_WAIT applies only to sockets that were connected. It exists only to re-transmit FIN-ACK if that is requested from peer. Listener socket is not connected, it only waits for SYN. In fact, it is perfectly OK, if listener accepts connection, then this side initiates "close" and then the socket enters TIME_WAIT state, at which point both the listener and the socket in TIME_WAIT state co-exists. But if the listener is taken down, then it can not brought up until TIME_WAIT is gone. Here one must use SO_REUSEADDR. It sounds kind of wrong.

Can someone please clarify, why such situation exists?

This is rather question about knowledge, but it comes from the problem, that usage of SO_REUSEADDR is considered dangerous but it is used really only to prevent TIME_WAIT sockets from interfering with listeners.

Note. I'm not asking, how bring up Listener if socket in TIME_WAIT exists. I'd like to understand, why such limitation exists. Why presence of socket in TIME_WAIT affects ability to bring up listener?

avorop
  • 1
  • 1

0 Answers0