Getting Read timed out exception using spring boot connect app

Hi Experts,

I have developed a spring boot connect app and while calling the index page sometime I am getting Read timed out exception As I am loading project list on the index page of my app.

UI Error:

{
	"status": 500,
	"error": "Internal Server Error",
	"message": "I/O error on POST request for \"https://auth.atlassian.io/oauth2/token\": Read timed out; nested exception is java.net.SocketTimeoutException: Read timed out",
	"timeStamp": "Tue Nov 19 10:06:18 UTC 2019"

Error

Tomact serevr log

2019-11-19 10:06:18.346 ERROR 4728 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context
 with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on POST request
for "https://auth.atlassian.io/oauth2/token": Read timed out; nested exception is java.net.SocketTimeoutException: Read timed out] with root cause

java.net.SocketTimeoutException: Read timed out
        at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_181]
        at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_181]
        at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_181]
        at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_181]
        at sun.security.ssl.InputRecord.readFully(InputRecord.java:465) ~[na:1.8.0_181]
        at sun.security.ssl.InputRecord.read(InputRecord.java:503) ~[na:1.8.0_181]
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983) ~[na:1.8.0_181]
        at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:940) ~[na:1.8.0_181]
        at sun.security.ssl.AppInputStream.read(AppInputStream.java:105) ~[na:1.8.0_181]
        at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137) ~[httpcore-4.4.11.jar:4.4.11]
        at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153) ~[httpcore-4.4.11.jar:4.4.11]
        at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280) ~[httpcore-4.4.11.jar:4.4.11]
        at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138) ~[httpclient-4.5.9.jar:4.5.9]
        at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56) ~[httpclient-4.5.9.jar:4.5.9]
        at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259) ~[httpcore-4.4.11.jar:4.4.11]
        at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163) ~[httpcore-4.4.11.jar:4.4.11]
        at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:157) ~[httpclient-4.5.9.jar:4.5.9]
        at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273) ~[httpcore-4.4.11.jar:4.4.11]
        at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125) ~[httpcore-4.4.11.jar:4.4.11]
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272) ~[httpclient-4.5.9.jar:4.5.9]
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) ~[httpclient-4.5.9.jar:4.5.9]
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) ~[httpclient-4.5.9.jar:4.5.9]
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) ~[httpclient-4.5.9.jar:4.5.9]
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[httpclient-4.5.9.jar:4.5.9]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) ~[httpclient-4.5.9.jar:4.5.9]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.9.jar:4.5.9]
        at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:87) ~[spring-web-5.1.9.RELEASE.j
ar:5.1.9.RELEASE]
        at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-5.1.9.REL
EASE.jar:5.1.9.RELEASE]
        at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:735) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
        at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:670) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
        at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:608) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
        at com.atlassian.connect.spring.internal.request.oauth2.JwtBearerAccessTokenProvider.obtainAccessToken(JwtBearerAccessTokenProvider.java:65) ~[atlassian
-connect-spring-boot-core-2.0.1.jar:na]
        at org.springframework.security.oauth2.client.OAuth2RestTemplate.acquireAccessToken(OAuth2RestTemplate.java:221) ~[spring-security-oauth2-2.3.6.RELEASE.
jar:na]
        at org.springframework.security.oauth2.client.OAuth2RestTemplate.getAccessToken(OAuth2RestTemplate.java:173) ~[spring-security-oauth2-2.3.6.RELEASE.jar:
na]
        at org.springframework.security.oauth2.client.OAuth2RestTemplate.createRequest(OAuth2RestTemplate.java:105) ~[spring-security-oauth2-2.3.6.RELEASE.jar:n
a]
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:731) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
        at org.springframework.security.oauth2.client.OAuth2RestTemplate.doExecute(OAuth2RestTemplate.java:128) ~[spring-security-oauth2-2.3.6.RELEASE.jar:na]
        at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:670) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
        at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:311) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
        at com.empyra.fua.repository.JiraRepository.getIssueTypes(JiraRepository.java:48) ~[classes/:na]
        at com.empyra.fua.repository.JiraRepository$$FastClassBySpringCGLIB$$ad5a7cdf.invoke(<generated>) ~[classes/:na]
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) ~[spring-aop-5.1.9.RELEASE.jar:5.1.9.RE

How can increase read time for my app?
@epehrson @kkercz Any idea to fix this ? I am still getting this read timeout issue.

Hi,

I am still facing this issue, kindly can anyone help on this ?
@david.pinn @danielwester

I’m not familiar with Atlassian Connect Spring Boot, but it seems to me that the error is at the low-level HTTP connection level. It could be a problem with Atlassian’s OAuth token service, but then I’d expect that problem to be universally felt across the ecosystem; and that doesn’t seem to be the case.

My instinct would be to investigate how to change the timeout limit within the Spring HTTP client itself. Here are a couple of resources that might be useful to you, if you decide to move in that direction:

1 Like

@dchouksey89, did you see David’s post above?

We don’t normally provide support for Spring Boot itself here, but since you’ve also raised a DEVHELP issue about this, I take it you need more input here.

Spring’s HttpComponentsClientHttpRequestFactory maps “read timeout” to “socket timeout”, and the docs for Apache HTTP Components 4.2 suggest that the timeout is infinite (0) by default. I can’t find any mention of the defaults in the docs for 4.5, but I doubt that changed. Are you perhaps setting the timeout somewhere already?

If you want to try just setting a longer timeout, I think the solution described in the StackOverflow post Spring rest template readTimeOut looks promising. Can you try that out?

@Bean
public RestTemplateCustomizer readTimeoutCustomizer() {
    return restTemplate -> {
        HttpComponentsClientHttpRequestFactory clientRequestFactory = new HttpComponentsClientHttpRequestFactory();
        clientRequestFactory.setReadTimeout(12345);
        restTemplate.setRequestFactory(clientRequestFactory);
    };
}

Hmm, I have been seeing lately similar errors in logs:

org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://auth.atlassian.io/oauth2/token": auth.atlassian.io:443 failed to respond; nested exception is org.apache.http.NoHttpResponseException: auth.atlassian.io:443 failed to respond
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:666)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:559)
at com.atlassian.connect.spring.internal.request.oauth2.JwtBearerAccessTokenProvider.obtainAccessToken(JwtBearerAccessTokenProvider.java:65)
at org.springframework.security.oauth2.client.OAuth2RestTemplate.acquireAccessToken(OAuth2RestTemplate.java:221)
at org.springframework.security.oauth2.client.OAuth2RestTemplate.getAccessToken(OAuth2RestTemplate.java:173)
at org.springframework.security.oauth2.client.OAuth2RestTemplate.createRequest(OAuth2RestTemplate.java:105)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:648)
at org.springframework.security.oauth2.client.OAuth2RestTemplate.doExecute(OAuth2RestTemplate.java:128)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:287)

I ignored them as it seemed like something rare