I am trying to download large zip file from rest API but getting
org.apache.catalina.connector.ClientAbortException: java.io.IOException: connection reset by peer.
Because of connection closed – downloaded zip file is corrupted and I am not able to open it. I tried setting timeout properties but no luck. Also having nginx
api gateway configuration also for the service.
This is the stacktrace:
org.apache.catalina.connector.ClientAbortException: java.io.IOException: Connection reset by peer
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:351) ~[tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.connector.OutputBuffer.flushByteBuffer(OutputBuffer.java:776) ~[tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.connector.OutputBuffer.append(OutputBuffer.java:681) ~[tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:386) ~[tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:364) ~[tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:96) ~[tomcat-embed-core-9.0.38.jar!/:9.0.38]
at org.springframework.util.StreamUtils.copy(StreamUtils.java:166) ~[spring-core-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.http.converter.ResourceHttpMessageConverter.writeContent(ResourceHttpMessageConverter.java:137) ~[spring-web-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.http.converter.ResourceHttpMessageConverter.writeInternal(ResourceHttpMessageConverter.java:129) ~[spring-web-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.http.converter.ResourceHttpMessageConverter.writeInternal(ResourceHttpMessageConverter.java:45) ~[spring-web-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:227) ~[spring-web-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:280) ~[spring-webmvc-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.h
Configuration file:
server:
connection-timeout: -1
tomcat :
async-timeout: 60000
connectTimeout: 60000
requestTimeout: 60000
socketTimeout: 60000
This is Spring with Tomcat embedded server version 9.0.38.
2
Answers
Cause
This exception happens when the Tomcat server tries to write back response to the client but it finds that the connection has been closed from the client side. It could happen in the following situations from the client side before the server completes the request:
Web browser is closed
Web page is refreshed or navigated away
HTTP client closes the connection due to a socket timeout happens from client side
Solution
Check the behavior or HTTP request invocation code of the web clients(Browser or REST client) from client side, find out if any of the above situations happen.
If in some heavy load situation like too many concurrent requests hit the Historian Tomcat server intensively, the server may take too long to complete the requested operation, causing timeout occurs from the client side and connection gets closed by the client before the server writes the response. In this situation, user can consider increasing the socket timeout value for the HTTP Client, take the below sample Java code which sets the time out values for the HttpClient as a reference:
wish I was helpful.
Your log indicates ClientAbortException, which occurs when your HTTP client drops the connection with the server and this happened before the server could close the server socket Connection.
Also, it might your HTTP client disconnected.
This could have a couple of reasons:
You can fairly easily emulate the behavior: