Skip to content

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

Closed
@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions