Delphi 10.3.1, Indy 10.6.2.5366
We are using TIdHTTPServer
in a REST service, and we have problems with the TIdHttpServer
slowly using all the connections. MaxConnections
is 100.
When we are reaching 100 connections, no one can get any response from the service.
With netstat we can see the IP and peer port, and in OnCommandGet
/OnCommandOther
we are logging the IP and peer port, but none of the IP/ports matched the IP/ports in netstat with state ESTABLISHED.
But when we started also to log IP and peer port in OnConnect
, we could see the IP/ports from netstat.
So now we think that some of our connections are getting stuck between OnConnect
and OnCommandGet
/OnCommandOther
.
Not all of our customers experience this problem, but for some it only takes 2-10 days to reach the MaxConnections
.
The clients to the service are mobile devices, so we think it might have something to do with the quality of the internet connection when the connection is established?!
Can we do something to prevent this from happening?
The
OnConnect
event is fired immediately when a client connects, but theOnCommand...
events are not fired until a full HTTP request has been received. But you should definately be able to get viablePeerIP
/PeerPort
values in theOnCommand...
events.If your mobile devices are having issues with the stability of their connections, they may be dropping their end of the connections abnormally and the server's OS might not be able to react to that in a timely manner. That could certainly cause the server to end up with a bunch of dead connections on its end, at least for awhile.
In the
OnConnect
event, try assigning a reasonable non-infinite timeout to theAContext.Connection.ReadTimeout
property, or theAContext.Binding.SetKeepAliveValues()
method, and see if that helps with your issue.