How does java net SocketException Connection reset happen

We are seeing frequent java.net.SocketException: Connection reset errors in our logs for a component that calls a third party Web service that sends SMS messages.

Our application is written in Java and runs on top of Tomcat 5.5. It was written by contractors who are no longer with us. The current team has no real Java expertise, and we are unsure as to where the Connection reset error is actually coming from, and how to go about debugging.

The issue appears to be completely intermittent, and unrelated to the messages we are attempting to send.

Any suggestions on what the typical causes of this exception might be, and how we might proceed, are welcome.

The whole call stack is included below for completeness.

(com.companyname.mtix.sms is our component)

java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:168)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
    at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:77)
    at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:105)
    at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1115)
    at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1832)
    at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590)
    at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:995)
    at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
    at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
    at com.companyname.mtix.sms.services.impl.message.SendTextMessage.sendTextMessage(SendTextMessage.java:127)
    at com.companyname.mtix.sms.services.MessageServiceImpl.sendTextMessage(MessageServiceImpl.java:125)
    at com.companyname.mtix.sms.services.remote.MessageServiceRemoteImpl.sendTextMessage(MessageServiceRemoteImpl.java:43)
    at sun.reflect.GeneratedMethodAccessor203.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
    at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
    at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
    at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
    at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
    at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
    at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:453)
    at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
    at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at com.companyname.mtix.sms.http.filters.NoCacheFilter.doFilter(NoCacheFilter.java

@sarfarazszk
We couldn’t find any useful clues from the stack

There are many reasons for the problem of Connection reset: network timeout, protocol mismatch, scheduled restart, and so on.

Please check if there are any large files processed during reset.

@sarfarazszk,

Moreover, you may also brows/google internet to get some relevant threads to sort out your issue. For example, see the following threads for your reference.
https://stackoverflow.com/questions/62929/java-net-socketexception-connection-reset
https://stackoverflow.com/questions/58741725/why-do-i-keep-getting-a-java-net-socketexception-connection-reset-error
https://www.mastertheboss.com/java/how-to-solve-the-error-java-net-socketexception-connection-reset/#:~:text=“Connection%20reset”%20simply%20means%20that,data%20on%20the%20output%20stream
etc.

The “java.net.SocketException: Connection reset” errors occurring in your Java application calling a third-party SMS web service can result from various factors, including network instability or issues with the third-party service. Given your team’s limited Java expertise and intermittent nature of the problem, it’s advisable to start by checking the third-party service’s status and availability. Additionally, ensure your server’s network connections are stable and not subject to firewall restrictions. If the issue persists, considering the absence of in-house Java expertise, you might consider consulting with a Java developer or experienced support team to diagnose and resolve the problem effectively.

@delonbest,
You can refer to @amjad.sahi previous response to locate and solve the issue.

If it still cannot be resolved, would you like to provide sample code and file? We will check it soon.