Skip to content

RestTemplate's connection/read timeout settings not applied when using Apache HttpClient [SPR-11442] #16068

Closed

Description

@spring-projects-issues

Jongwook Choi opened SPR-11442 and commented

To use Apache HttpClient as a backend of RestTemplate, one should use HttpComponentsClientHttpRequestFactory. However,

The methods

  • HttpComponentsClientHttpRequestFactory#setConnectTimeout(int timeout)
  • HttpComponentsClientHttpRequestFactory#setReadTimeout(int timeout)

are not working since Spring 4.0.0. (affected versions are: 4.0 GA, 4.0.1, 4.0.2 and current master)
The version of Apache HttpClient used is 4.3.2 (the latest as of now - Spring 4 requires HttpClient 4.3+)

Actually, the timeout is overwritten to zero on execution, and therefore it might cause an unexpected hang.
In the old version of spring (e.g. 3.2.x) everything works fine. (see the test in the reference URL)

More details I've figured out:

  • HttpComponentsClientHttpRequest is created well with the timeout settings configured.
    (The configuration is hold in an instance of RequestConfig, contained in a HttpContext)
  • But when the request it is executed, RequestConfig is overwritten completely.
    (see the line 806 of AbstractHttpClient.java of HttpClient 4.3)
  • I suspect the cause is commit 296e2189 (Support an asynchronous API for RestTemplate [SPR-8804] #13446).

Affects: 4.0.2

Reference URL: https://gist.github.com/wookayin/9087154

Issue Links:

0 votes, 6 watchers

Activity

  1. spring-projects-issues commented on Feb 26, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Alex Adeyemo commented

    I don't think this is a bug.

    The reporter didn't pass HttpComponentsClientHttpRequestFactory to the resttemplate.

    Check the gist posted https://gist.github.com/wookayin/9087154

  2. spring-projects-issues commented on Feb 26, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Indeed, the test passes once the HttpComponentsClientHttpRequestFactory is actually passed into RestTemplate.

    I'm marking this as 'invalid' for the time being; to be reopened if any issues remain.

    Juergen

  3. spring-projects-issues commented on Feb 28, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Jongwook Choi commented

    Sorry, there was a little mistake. Thanks for pointing out it.

    I've updated the gist to revision 3, making the HCCHRF being passed into RestTemplate. The test still passes as you mentioned, but the problematic situation is: injecting an explicitly created instance of DefaultHttpClient into the HCCHRF. Then the test fails (passes in 3.2.x however).

    Since DefaultHttpClient is deprecated as of 4.2, using HttpClientBuilder (introduced in 4.3+) did not cause the problem. Although Spring 4.x depends on HttpClient 4.3+, I feel that the deprecated API could be supported also, to ensure compatibilities with third-party (spring-dependent) modules.

    Thanks.
    Jongwook Choi

  4. spring-projects-issues commented on Feb 28, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Thanks for the update. I'll have a look at that specific case; looks like we could be more careful with out RequestConfig overriding there.

    Juergen

  5. spring-projects-issues commented on Mar 4, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    Juergen Hoeller, I have a PR available with a candidate implementation. Could you please review it? Thanks!

  6. spring-projects-issues commented on Mar 10, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Stéphane, this looks alright to me. Please go ahead and merge it into master...

    Juergen

  7. spring-projects-issues commented on Mar 10, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    This has been merged to master.

  8. added
    type: regression
    in: web
    on Jan 11, 2019
  9. added this to the 4.0.3 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webtype: regression

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions