In recent versions org.springframework.web.util.DisconnectedClientHelper
was added. But we are facing some other sort of exceptions. Here is a sample stack trace
Unhandled exception org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: I/O error while reading input message; nested exception is org.apache.catalina.connector.ClientAbortException: java.net.SocketException: Connection reset
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:555)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:623)
.......................................
Caused by: org.springframework.http.converter.HttpMessageNotReadableException: I/O error while reading input message; nested exception is org.apache.catalina.connector.ClientAbortException: java.net.SocketException: Connection reset
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:197)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:160)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:133)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:122)
............................................
Caused by: org.apache.catalina.connector.ClientAbortException: java.net.SocketException: Connection reset
at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:315)
at org.apache.catalina.connector.InputBuffer.checkByteBufferEof(InputBuffer.java:590)
............................................
Caused by: java.net.SocketException: Connection reset
at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:394)
at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:426)
This kind of disconnect is not covered by Helper.
So, is it an oversight, or there is a distinct difference between handled EXCEPTION_PHRASES = .... "connection reset by peer"
and not handled Connection reset
?
Comment From: sbrannen
Hi @KazzmanK,
Congratulations on submitting your first issue for the Spring Framework! 👍
So, is it an oversight, or there is a distinct difference between handled
EXCEPTION_PHRASES = .... "connection reset by peer"
and not handledConnection reset
?
I believe we simply were not aware of that particular Connection reset
exception message when that code was written.
Thus, in commit 203fa7519692a3d12a4eca73765ba6592b164fd3 I've made this more lenient to match any exception message containing connection reset
(ignoring case).
This will be available in 6.1.10, but you can also try it out in a 6.1.10 snapshot.
Cheers,
Sam
Comment From: KazzmanK
Hi! Thank you!
I believe we simply were not aware of that particular
Connection reset
exception message when that code was written.
We are here were wondering, is there a real difference in such exceptions, say one initiated by client or network failure, other by server failure.
Comment From: sbrannen
Hi! Thank you!
You're welcome.
We were wondering, is there a real difference in such exceptions, say one initiated by client or network failure, other by server failure.
DisconnectedClientHelper
makes a best-effort attempt at determining if the most specific exception (original exception) in the exception chain indicates that the "client has gone away".
For your particular use case, Tomcat throws a ClientAbortException
which indicates "an abort of a request by a remote client" with a SocketException
as the root cause.