2
There's a single client application that makes frequent TCP (HTTP) connections to the server. Connection lasts for the duration of one request and then server closes the connection so socket on the server ends up in TIME_WAIT state for few minutes. As client application makes repeated requests the number of TIME_WAIT connections on server grows and settles on ~150 sockets being in TIME_WAIT constantly.
Occasionally new connection from client chooses a recently used ephemeral source port that is in TIME_WAIT state on the server and connection fails. With 32k ephemeral port range and 150 sockets in TIME_WAIT there's >10% chance of this happening. Exact scenario is also described in RFC6056 section 2.3
I have no control on the server so reducing TIME_WAIT delay or changing behavior is not an option. It is also difficult to change client app in order to pick source port manually as I am using a 3rd party library to make HTTP requests.
Increasing ephemeral port range would only slightly decrease probability of collision. Is there a way to change ephemeral port selection strategy on a client (Linux) to avoid such collisions?
1
If you have control over the client, the cleaner way would be to make it use a persistent HTTP connection. The probability that the 3rd party library supports that somehow (or can be changed to do it) is comparatively high.
– dirkt – 2017-02-15T14:32:01.023It does indeed. But the server forcefully closes the connection regardless of client setting Keep-Alive – senyacap – 2017-02-15T20:51:56.093
You should work on this problem from some other side. Trying to get a really bad design to work a little bit better is going to take maximum effort and produce minimum return. The optimum means of attack depends on specifics you haven't mentioned such as the precise relationship of whoever you are doing this for and whoever runs the server as well as what other resources are available to you. – David Schwartz – 2017-03-01T20:46:18.340