Im using Spring RestTemplate
to make rest call to another service (NodeJS service). Intermittently getting connection reset errors. Same code was working fine with JDK 8 and Spring boot 2.0.1, after upgrading to Amazon Corretto JDK 11 and Spring boot 2.1.5, started seeing this issue.
Caused by: javax.net.ssl.SSLException: Connection reset
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:127)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:321)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:259)
at java.base/sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1314)
Suppressed Exception:
org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:735)
... 143 common frames omitted
Suppressed: java.net.SocketException: Broken pipe (Write failed)
at java.base/java.net.SocketOutputStream.socketWrite0(Native Method)
at java.base/java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:110)
at java.base/java.net.SocketOutputStream.write(SocketOutputStream.java:150)
Some blogs mentioned that JDK 11 had issue with TLS1.3
- Tried setting up with
-Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2
- Tried setting
SocketFactory
with these protocols toRestTemplate
. - Tried increasing
socketTimeout
for reset client.
Still no luck.
#Code:#
HttpHeaders headers = new HttpHeaders();
headers.set(AUTHORIZATION, getHeader());
headers.set(OAuth2AccessToken.ACCESS_TOKEN, token);
HttpEntity<String> entity = new HttpEntity<String>(headers);
ResponseEntity<Object> resEntity = null;
resEntity = this.restTemplate.exchange(checkTokenEndpointUrl,
HttpMethod.GET, entity, Object.class);
It should not throw intermittent connection reset error