Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-2136

Idle HTTP connections remain open

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Invalid
    • 4.5.13
    • None
    • HttpClient (classic)
    • None

    Description

      We found out, that Apache HTTPClient sends HTTP header "Connection: keep-alive" by default.

      This behaviour can cause problems on some networks (e.g. Azure network).

      For our implementation we use Spring RestTemplate in combination with Apache HTTPClient (to support PATCH http requests). As soon as we used Apache HTTPClient we had trouble with some connections, but only on the Azure App Service (Azure network) - not locally.

      Our backend app opens connections to other services which are not closed, so the tcp connection remains open. The opposition sends tcp FIN after some minutes (5 minutes in our case), but the tcp FIN never reaches our app service. Something in the Azure network kills the idle tcp connection, but the application still holds the damaged tcp connections and tries to send data. With no socket read timeout implemented some unspecific time later the following exception occurs: "java.net.SocketException: Operation timed out (Read failed)". With configured socket read timeout the data read timeout exception occurs after the defined time, but this doesn't solve the main reason of the broken tcp connection.

      We found some workaround solutions like a connection pool which close idle connections after 3 minutes. But in our case we don't want the default behaviour to keep all connections open with keep-alive. Our final implementation is to set the HTTP header field "Connection: close".

      I think "keep-alive" is not a good default value for the HTTP header field "Connection".

      We heard that this issue happens on other networks (AWS), too. It seems to be a common practice to close idle connections in networks which use SNAT port allocation.

       

       

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            linda.werner Linda Werner
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: