TIME_WAIT and MaxUserPort – what it is, what it does, when it’s important – Blog du Tristank
Posted by jpluimers on 2018/08/01
Despite many posts saying you can use it on other than outbound connections, lets quote that it doesn’t:
MaxUserPort controls “outbound” TCP connections
[WayBack] MaxUserPort is used to limit the number of dynamic ports available to TCP/IP applications.
…
It’s never going to be an issue affecting inbound connections.
MaxUserPort is not the right answer if you think you have an inbound connection problem.
Source: [WayBack] MaxUserPort – what it is, what it does, when it’s important – Blog du Tristank
The side of the TCP connection that closes is gets the TIME_WAIT state, which means you should avoid your server to terminate connections because it then will run out of available ports. Clients should disconnect when done (or when done for the foreseeable future) otherwise the server gets the 2MSL TIME_WAIT penalty as for instance explained by [WayBack] TIME_WAIT and its design implications for protocols and scalable client server systems – AsynchronousEvents.
The solution for inbound connections is that your TCP based protocol should enforce either the client to close the connection, or to use some form of client pooling so there is no need for many connection setup/teardowns of short lived connections.
TIME_WAIT can last for about ~10 minutes if you are unlucky.
More recommended reading:
- [WayBack] TIME_WAIT and its design implications for protocols and scalable client server systems – AsynchronousEvents
- [WayBack] TcpTimedWaitDelay
- [WayBack] draft-faber-time-wait-avoidance-00 – Avoiding the TCP TIME_WAIT state at Busy Servers
- [WayBack] Indy: IdTCPClient leaves connection in status TIME_WAIT
- [WayBack] Large number of TCP connections with Time_Wait status – Remoting SDK – RemObjects Talk
- [WayBack] sockets – TCP option SO_LINGER (zero) – when it’s required – Stack Overflow
- [WayBack] delphi – Force Http 1.0 idHttpServer and TIME_WAIT – Stack Overflow
- [WayBack] Transmission Control Protocol – Wikipedia
- Diagrams:
- [WayBack] TCP states – explained – Apigee Community
–jeroen
Leave a Reply