Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-11051

Fix incorrect HttpClient usage leading to TCP sockets stuck in CLOSE_WAIT

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 5.6
    • Fix Version/s: 5.6.0-HF13, 5.7.1
    • Component/s: None

      Description

      We may be leaving connections around: many connections staying in CLOSE_WAIT state, when seen with netstat.

      Audit our code to be sure.

      Apache HttpClient holds TCP connections, but they are usually not released automatically when the client object is forgotten at the end of a method, even though the HttpMethod (either PostMethod, PutMethod, GetMethod, ...) has fully consumed its result. Even calling httpMethod.releaseConnection() is not enough as it may just release the connection to the pool and not close it.

      To fix this, there are several possibilities:

      • call addHeader("Connection", "close"); on the HttpMethod to make it be used only once then closed,
      • call ConnectionManager.closeIdleConnections when done,
      • have proper reuse of the HttpClient objects during the lifetime of the server.

      The first two don't make use of any pooling so are a bit more inefficient, but it's better than leaving connections around anyway.

      See blog: http://www.nuxeo.com/blog/development/2013/02/using-httpclient-properly-avoid-closewait-tcp-connections/

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: