Apache Http client prints "[read] I / O error: read timed out" "

I use apache http client v4.5 and use it as a REST client. In some cases, I recognize the "[read] I / O error: Read timed out" error, which comes from the httpclient infrastructure when it reads the received content and displays it as the last message.

This does not seem to affect, but I wonder if anyone has an idea where it comes from and how it can be solved. According to the following chain ( link ), there seems to be a problem with the "mutlithreaded" configuration.

However, I only use the default http client configuration, and while I am using version v4, I don’t know how I can set multithreading to false to see if it matters.

I also tried to set timeouts, but that did not help.

Any clues?

Log:

15:48:05.984 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "HTTP/1.1 200 OK[\r][\n]" 15:48:05.984 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "Date: Tue, 29 Dec 2015 14:48:03 GMT[\r][\n]" 15:48:05.984 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "Server: Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.6.8[\r][\n]" 15:48:05.984 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "X-Powered-By: PHP/5.6.8[\r][\n]" 15:48:05.985 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "Cache-Control: nocache, private[\r][\n]" 15:48:05.985 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "Content-Length: 99[\r][\n]" 15:48:05.985 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "Keep-Alive: timeout=5, max=99[\r][\n]" 15:48:05.985 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "Connection: Keep-Alive[\r][\n]" 15:48:05.985 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "Content-Type: application/json[\r][\n]" 15:48:05.985 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "[\r][\n]" 15:48:05.985 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "{"success":true,"data":{"id":1946,"location":"http:\/\/localhost:9001\/shop\/api\/articles\/1946"}}" 15:48:06.016 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "[read] I/O error: Read timed out" 

my Http client initialization

 HttpClientBuilder httpBuilder = HttpClientBuilder.create(); // set timeout did not helped // RequestConfig.Builder requestBuilder = RequestConfig.custom(); // requestBuilder = requestBuilder.setConnectTimeout(timeout); // requestBuilder = requestBuilder.setConnectionRequestTimeout(timeout); // requestBuilder = requestBuilder.setSocketTimeout(timeout); // httpBuilder.setDefaultRequestConfig(requestBuilder.build()); HttpClient httpClient = httpBuilder.build(); 
+7
java multithreading timeout
source share
2 answers

I am using httpclient 4.5.2, and in my case setting timeouts on request helped:

 HttpPost postRequest = new HttpPost("https://..."); postRequest.setHeader(..., ...); RequestConfig requestConfig = RequestConfig.custom() .setSocketTimeout(1000) .setConnectTimeout(1000) .build(); postRequest.setConfig(requestConfig); 
+2
source

One of the reasons for this error may be that the server follows the policy of closing HTTP connections after a response. If so, then this error can be avoided by disabling the reuse of the connection by the client, so the client will not need to check that the connection is still alive:

 httpBuilder.setConnectionReuseStrategy( (response, context) -> false ); 
0
source

All Articles