Skip to content

Bug: Apache HttpClient is not properly configured #715

@chanseokoh

Description

@chanseokoh

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);

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions