Fix issues with thread leakage#326
Conversation
|
The server will not wait indefinitely if a client fails to disconnect cleanly. The OS itself will eventually timeout internally (may take up to several minutes) and invalidate the connection, which will then cause the socket to report errors that Indy catches so it can close the socket and cleanup the owning thread. That delay can be mitigated by enabling TCP keepalives on the connection (such as via That being said, there is a logical difference between the time the server should wait for a new request to arrive, versus the time the server should wait for individual bytes of that request to arrive. Your proposal is not making that distinction, only handling the latter case. And, you are only applying that timeout to I already have pending code changes for adding new Also, can you please separate the HL7 changes into a separate pull request? That has nothing to do with this |
If you're running a general purpose http server on the internet using indy, some clients will get disconnected without closing the socket. If that happens, and if the server is holding the connection open, then the thread waiting to hear from the client will wait indefinitely. This will lead to a leak of 3 threads (one from Indy, 2 from windows) for each time this happens. Over time, the server will run out of threads.
This fix allows for the server to set a connection time out - if the client hasn't been heard from for more than x seconds (setting when the server is created), the connection will be closed by the server, and the threads won't leak.