1

I'm using SpringBoot with JDK 11. This application is deployed on a container (AWS).

Into my REST Controllers I need to call internally external REST api services (using TLS 1.2) I'm using java.net.http.HttpClient for this.

httpClient = HttpClient.newHttpClient();

(I'm using only one httpClient for all requests)

Sometimes (randomically) these requests fail. Into my logs I see as cause of this problem:

Connection reset by peer

This is strange for me. As already explained, this error does not happen systematically.

I analysed my code but I don't notice anything wrong.

Any suggestion?

Is the HttpClient initialization correct?

Is possible that the cause it's related to my code or from the external services?

Any suggestions are welcome.

Safari
  • 11,437
  • 24
  • 91
  • 191
  • 1
    Does this help: https://stackoverflow.com/questions/1434451/what-does-connection-reset-by-peer-mean? – Seelenvirtuose Oct 15 '20 at 16:35
  • 1
    How frequent the issue is? If it's not frequent then adding a retry would make sense, else debug the network traffic, not sure if increasing connection timeout would help (but give it a try). – Vishrant Oct 15 '20 at 16:42
  • completely random.. sometimes 8% of the requests fails, sometimes 4% sometimes 0% – Safari Oct 16 '20 at 06:49
  • Do you know what version of the HTTP protocol your requests are being sent with? The `HttpClient` uses a connection pool for HTTP/1.1 requests - and it is possible that the server's policy for idle connections has a keepalive timeout that is less than the default `HttpClient` keepalive time. That might increase the chances of having the connection arbitrarily closed by the server side while the client is attempting to send a new request. You could try playing with `-Djdk.httpclient.keepalive.timeout=` ad see if it changes anything. – daniel Oct 16 '20 at 11:04
  • in this my case, I don't understand if it's better to have very long timeout values or not. What's the default value for httpClient (if I understand correctly, the default it's 20m). – Safari Oct 19 '20 at 08:25

0 Answers0