Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Apache HttpClient is not properly configured #715

Closed
chanseokoh opened this issue Jun 13, 2019 · 0 comments · Fixed by #717
Closed

Bug: Apache HttpClient is not properly configured #715

chanseokoh opened this issue Jun 13, 2019 · 0 comments · Fixed by #717
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@chanseokoh
Copy link
Contributor

Just hit this bug.

Versions:

  • google-http-client: 1.30.1
  • google-http-client-apache-v2: 1.30.1

Here, the code is supposed to configure HttpClient with some curated values, but in reality, most of them are being ignored. I'll mark below which values are ignored:

    // IGNORED
    SocketConfig socketConfig = SocketConfig.custom()
        .setRcvBufSize(8192)  // IGNORED
        .setSndBufSize(8192)  // IGNORED
        .build();

    PoolingHttpClientConnectionManager connectionManager =
        new PoolingHttpClientConnectionManager(-1, TimeUnit.MILLISECONDS);
    connectionManager.setValidateAfterInactivity(-1);

    return HttpClientBuilder.create()
        .useSystemProperties()
        // IGNORED
        .setSSLSocketFactory(SSLConnectionSocketFactory.getSocketFactory())
        .setDefaultSocketConfig(socketConfig)  // IGNORED
        .setMaxConnTotal(200)  // IGNORED
        .setMaxConnPerRoute(20)  // IGNORED
        .setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault()))
        .setConnectionManager(connectionManager)
        .disableRedirectHandling()
        .disableAutomaticRetries()

The reason is apparent from the Javadocs of the methods. For example, setDefaultSocketConfig says

     * Please note this value can be overridden by the {@link #setConnectionManager(
     *   org.apache.http.conn.HttpClientConnectionManager)} method.

That is, calling setConnectionManager() makes the custom values set through the methods irrelevant. You can actually check this behavior in the build() method. For example,

        if (connManagerCopy == null) {
                ...
                // defaultSocketConfig is meaningful only when not calling setConnectionManager().
                poolingmgr.setDefaultSocketConfig(defaultSocketConfig);
@chingor13 chingor13 self-assigned this Jun 13, 2019
@chanseokoh chanseokoh changed the title Bug: Apache HttpClient is not property configured Bug: Apache HttpClient is not properly configured Jun 13, 2019
@chingor13 chingor13 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jun 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants