title: What is the cost of many TIME_WAIT on the server side?
body: <p>Let's assume there is a client that makes a lot of short-living connections to a server.</p>
  
  <p>If the client closes the connection, there will be many ports in <code>TIME_WAIT</code> state on the client side.  Since the client runs out of local ports, it becomes impossible to make a new connection attempt quickly.</p>
  
  <p>If the server closes the connection, I will see many <code>TIME_WAIT</code>s on the server side.  However, does this do any harm?  The client (or other clients) can keep making connection attempts since it never runs out of local ports, and the number of <code>TIME_WAIT</code> state will increase on the server side.  What happens eventually?  Does something bad happen? (slowdown, crash, dropped connections, etc.)</p>
  
  <p>Please note that my question is not "What is the purpose of <code>TIME_WAIT</code>?" but "What happens if there are so many <code>TIME_WAIT</code> states on the server?" I already know what happens when a connection is closed in TCP/IP and why <code>TIME_WAIT</code> state is required.  I'm not trying to trouble-shoot it but just want to know what is the potential issue with it.</p>
  
  <p>To put simply, let's say <code>netstat -nat | grep :8080 | grep TIME_WAIT | wc -l</code> prints <code>100000</code>.  What would happen?  Does the OS's network stack slow down?  "Too many open files" error? Or, just nothing to worry about?</p>