Server port exhaustion occurs when a server runs out of available ports to use for new connections. This can create significant problems for server reliability and availability.
When a server initiates the close of a TCP connection and enters the TIME_WAIT state, the port used for that connection remains occupied for the duration of the TIME_WAIT period. Since most servers handle hundreds or thousands of connections simultaneously, having multiple ports in TIME_WAIT can quickly deplete the available ports.
Consequently, the server may struggle to accept new connections, even though it has the capacity to process them because the ports are still tied up.
Examples of situations where this issue may arise include:
- Heavy traffic on a web server leading to many connections being closed frequently
- Short-lived tasks that create and close many connections in a short period
- Stress testing a server with rapid connection opens and closes