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

Handle java.net.SocketException: Connection reset more gracefully

    XMLWordPrintableJSON

Details

    Description

      Currently in edge cases the retry mechanism leveraging DefaultHttpRequestRetryHandler does not catch "Connection reset" exceptions. This is caused by

      1. A connection pool which keeps the connections alive for too long
      2. The reduced default validation of connections in https://hc.apache.org/httpcomponents-client-4.5.x/current/httpclient/apidocs/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.html: "The code now only checks the connection if the elapsed time since the last use of the connection exceeds the timeout that has been set. The default timeout is set to 2000ms"

      The error scenario is as follows:

      1. A client opens a number of connection almost in parallel which exceed the number of retries
      2. then the connections are reused shortly before they are closed silently by some proxy or the server.
      3. Now the client tries to reuse those but runs into the "Connection reset" issue. Although it will retry through DefaultHttpRequestRetryHandler 3 different pooled connections they all suffer from the fact that they are not longer accepted (and therefore throw the same SocketException).

      Maybe one could improve the resilience by calling https://hc.apache.org/httpcomponents-client-4.5.x/current/httpclient/apidocs/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.html#setValidateAfterInactivity(int) with 0 on the underlying connection pool manager until a connection is successfully established to that host again.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              kwin Konrad Windszus
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: