HttpComponents HttpClient
  1. HttpComponents HttpClient
  2. HTTPCLIENT-1168

HTTPClient doesn't send authentication header in threaded environment

    Details

      Description

      Using HTTPClient with multiple threads and basic authentication seems to create a race condition. The request headers sometimes don't contain the authorization entry, which results in a 401 (although the username and password credentials are correctly set).

        Activity

        Hide
        Lennart Diedrich added a comment -

        Simple test to demonstrate the issue.

        Show
        Lennart Diedrich added a comment - Simple test to demonstrate the issue.
        Hide
        Oleg Kalnichevski added a comment -

        Lennart,

        The race condition is caused by HttpContext instance being shared for all threads of execution. While theoretically HttpContext can be shared by multiple execution threads, authentication state clearly cannot.

        I'll see if I can fix this issue by synchronizing access to AuthState instances or by updating the documentation.

        Oleg

        Show
        Oleg Kalnichevski added a comment - Lennart, The race condition is caused by HttpContext instance being shared for all threads of execution. While theoretically HttpContext can be shared by multiple execution threads, authentication state clearly cannot. I'll see if I can fix this issue by synchronizing access to AuthState instances or by updating the documentation. Oleg
        Hide
        Oleg Kalnichevski added a comment -

        AuthState instances are inherently thread unsafe as they maintain conversation state that can span across multiple HTTP exchanges. I opted for just documenting the recommended way of using HttpContext in multithreaded applications (one HttpContext instance per thread of execution).

        Oleg

        Show
        Oleg Kalnichevski added a comment - AuthState instances are inherently thread unsafe as they maintain conversation state that can span across multiple HTTP exchanges. I opted for just documenting the recommended way of using HttpContext in multithreaded applications (one HttpContext instance per thread of execution). Oleg

          People

          • Assignee:
            Unassigned
            Reporter:
            Lennart Diedrich
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development