Solr
  1. Solr
  2. SOLR-6245

Socket and Connection configuration are ignored in HttpSolrServer when passing in HttpClient

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.7, 4.8, 4.9
    • Fix Version/s: 4.10, 6.0
    • Component/s: clients - java
    • Labels:
      None

      Description

      I spent time debugging our HttpSolrServer and HttpClient. We construct our HttpClient (we have some requirement regarding about connectionTimeout, soTimeout, etc.) and then pass it to HttpSolrServer. I found out that all our socket level and connection level configuration are ignored when creating a http connection.

      The problem is in HttpClient 4.3.X, they allow overriding of these parameters per request i.e. one request can have socketTimeout=100ms and another request can have socketTimeout=200ms. The logic[1] to check whether to make it per-request base config or not depending on whether any of these parameters is set.

       protected NamedList<Object> executeMethod(HttpRequestBase method, final ResponseParser processor) throws SolrServerException {
      // XXX client already has this set, is this needed?
      method.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS,
      followRedirects);
      method.addHeader("User-Agent", AGENT);
      

      In HttpSolrServer.java, only one parameter (HANDLE_REDIRECTS) is set but that trigger the logic in HttpClient to initialize a default per-request base config, which eventually override any socket and connection configuration, we did via HttpClientBuilder.

      To conclude, a solution would be to remove these line

      // XXX client already has this set, is this needed?
      method.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS,
      followRedirects);
      

      [1] - http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java?revision=1603745&view=markup [LINE:172]

      1. SOLR-6245.patch
        4 kB
        Shalin Shekhar Mangar
      2. SOLR-6245.patch
        3 kB
        Shalin Shekhar Mangar
      3. SOLR-6245.patch
        3 kB
        Shalin Shekhar Mangar

        Activity

        Hide
        Shalin Shekhar Mangar added a comment -

        Great catch! Thanks for reporting this.

        The attached patch removes those lines and adds a test which fails with them.

        Show
        Shalin Shekhar Mangar added a comment - Great catch! Thanks for reporting this. The attached patch removes those lines and adds a test which fails with them.
        Hide
        Shalin Shekhar Mangar added a comment -

        Added some javadocs on the new test method to explain the situation.

        Show
        Shalin Shekhar Mangar added a comment - Added some javadocs on the new test method to explain the situation.
        Hide
        Shalin Shekhar Mangar added a comment -

        Moved the testcase into a new test so that we can use SupressSSL annotation on it. I cannot reconcile the SSL configuration with the new HttpComponents API and I don't have time to work on it further. But coverage wise we're good because the fix is adequately tested.

        Show
        Shalin Shekhar Mangar added a comment - Moved the testcase into a new test so that we can use SupressSSL annotation on it. I cannot reconcile the SSL configuration with the new HttpComponents API and I don't have time to work on it further. But coverage wise we're good because the fix is adequately tested.
        Hide
        Shalin Shekhar Mangar added a comment -

        Thanks Patanachai!

        Show
        Shalin Shekhar Mangar added a comment - Thanks Patanachai!

          People

          • Assignee:
            Shalin Shekhar Mangar
            Reporter:
            Patanachai Tangchaisin
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development