Skip to content
Fix Code Error

What’s causing my java.net.SocketException: Connection reset?

March 13, 2021 by Code Error
Posted By: Richard E

We are seeing frequent but intermittent java.net.SocketException: Connection reset errors in our logs. 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 unrelated to the messages we are attempting to send.
Note that the message is not connection reset by peer.

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

Here is a representative stack trace (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:63)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at com.companyname.mtix.sms.http.filters.MessageFilter.doFilter(MessageFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:61)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.ajaxanywhere.AAFilter.doFilter(AAFilter.java:46)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)
    

Our component is a web application, running under Tomcat, that calls a third party Web service that sends SMS messages, it so happens. The line of our code on which the exception gets thrown from is the last line in the code snippet below.

String aggregatorResponse = null;
HttpClient httpClient = prepareHttpClient( username, password );
PostMethod postMethod = preparePostMethod( textUrl );

try {
  SybaseTextMessageBuilder builder = new SybaseTextMessageBuilder();
  URL notifyUrl = buildNotificationUrl( textMessage, codeSetManager );
  String smsRequestDocument = builder.buildTextMessage( textMessage, notifyUrl );
  LOG.debug( "Sybase MT document created as: n" + smsRequestDocument );

  postMethod.setRequestEntity( new StringRequestEntity( smsRequestDocument ) );
  LOG.debug( "commiting SMS to aggregator: " + textMessage.toString() );
  int httpStatus = httpClient.executeMethod( postMethod );

Solution

The javadoc for SocketException states that it is

Thrown to indicate that there is an error in the underlying protocol such as a TCP error

In your case it seems that the connection has been closed by the server end of the connection. This could be an issue with the request you are sending or an issue at their end.

To aid debugging you could look at using a tool such as Wireshark to view the actual network packets. Also, is there an alternative client to your Java code that you could use to test the web service? If this was successful it could indicate a bug in the Java code.

As you are using Commons HTTP Client have a look at the Common HTTP Client Logging Guide. This will tell you how to log the request at the HTTP level.

Answered By: Mark

Related Articles

  • Can't access Eclipse marketplace
  • How do I deal with installing peer dependencies in…
  • Plugin…
  • Best way to extract messy HTML tables using BeautifulSoup
  • Failed to execute goal…
  • Logging best practices
  • SVG Mask is "bleeding" on canvas edges
  • How to convert image into byte array and byte array…
  • Maven2: Missing artifact but jars are in place
  • Eclipse will not start and I haven't changed anything
  • Pivoting a defined number of rows into columns…
  • When I'm testing a web app by JUnit and Mockito I…
  • TLS 1.3 server socket with Java 11 and self-signed…
  • Name [jdbc/mydb] is not bound in this Context
  • Javax.net.ssl.SSLHandshakeException:…
  • Exception in thread "JobGenerator"…
  • Problems using Maven and SSL behind proxy
  • How to configure Ubuntu as router in Vagrant
  • Jetty server throws idle timeout for REST calls
  • SQLException: No suitable Driver Found for…
  • How to handle invalid SSL certificates with Apache…
  • XAMPP Port 80 in use by "Unable to open process" with PID 4
  • How do I solve this error, "error while trying to…
  • What is a stack trace, and how can I use it to debug…
  • Java Hashmap: How to get key from value?
  • Change multiple SVG paths in CSS on hover or with javaScript
  • "gatsby-source-airtable" threw an error while…
  • Why am I getting a "401 Unauthorized" error in Maven?
  • Error: error getting endorser client for channel:…
  • Neither BindingResult nor plain target object for…
  • Trouble with Next js + Express deployment using Zeit Now
  • Android Gradle plugin 0.7.0: "duplicate files during…
  • How to set level logging to DEBUG in Tomcat?
  • How to blur the background after click on the button…
  • Is there a way to get all IP addresses of youtube to…
  • "Non-resolvable parent POM: Could not transfer…
  • Bootstrap - center child when parent isn't centered…
  • Throw HttpResponseException or return…
  • Spring batch keeps writing record after exception
  • How to install npm peer dependencies automatically?
  • Tomcat 7 "SEVERE: A child container failed during start"
  • UnsatisfiedDependencyException: Error creating bean…
  • How to check if a String is numeric in Java
  • Using enums in a spring entity
  • Send a SMS via intent
  • java.lang.ClassNotFoundException: HttpServletRequest
  • PySpark 3 - UDF to remove items from list column
  • NoClassDefFoundError while trying to run my jar with…
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • How to Map json file in React
  • Laravel + Vue.js. Load more data when i click on the button
  • Add multiple items to a list
  • error LNK2005: ✘✘✘ already defined in…
  • Controller method does not updates data
  • How to upload a file using Java HttpClient library…
  • Exception in thread "main"…
  • vue/cli 3 unmet dependencies
  • JPA Hibernate Persistence exception…
  • open telemetry InMemorySpanExporter not reseting…
  • TypeError: Cannot read property 'webpackJsonp' of undefined
  • How do I fix the npm UNMET PEER DEPENDENCY warning?
  • Requested bean is currently in creation: Is there an…
  • Why the REPL is not showing the full trace of the…
  • render function or template not defined in…
  • Is this very likely to create a memory leak in Tomcat?
  • java.lang.NoClassDefFoundError:…
  • #define macro for debug printing in C?
  • Pivot aggregates in SQL
  • Mock MQRFH2 header in JUnit Testing Error [MQRFH2…
  • What is the maximum size of an http response?
  • How to prevent scrolling the whole page?
  • Unfortunately MyApp has stopped. How can I solve this?
  • Do HttpClient and HttpClientHandler have to be…
  • useEffect Error: Minified React error #321 (GTM…
  • Content is not allowed in Prolog SAXParserException
  • How to solve this java.lang.NoClassDefFoundError:…
  • Access-Control-Allow-Origin is not allowed by…
  • HTTP Status 500 - org.apache.jasper.JasperException:…
  • PHP parse/syntax errors; and how to solve them
  • Running a simple JSF webapp on TOMEE-9.0 PLUS cannot…
  • What is a NullReferenceException, and how do I fix it?
  • A fatal error has been detected by the Java Runtime…
  • Error message "Forbidden You don't have permission…
  • How can I pad a String in Java?
  • Unable to Build using MAVEN with ERROR - Failed to…
  • What is the difference between Amazon SNS and Amazon SQS?
  • What is the difference between CloseableHttpClient…
  • javascript .replace and .trim not working in vuejs
  • Program.Mattor(): not all code paths return a value.…
  • String isNullOrEmpty in Java?
  • Android – Listen For Incoming SMS Messages
  • ListView refreshes only on scroll up and down
  • How to pre-populate the sms body text via an html link
  • ActiveMQ Artemis in Docker shows empty screen
  • Issue with iron-ajax request
  • Aurelia CLI viewport does not render
  • How to use PrimeFaces p:fileUpload? Listener method…
  • commandButton/commandLink/ajax action/listener…
  • How can I throw CHECKED exceptions from inside Java…
  • Aurelia - Setting headers in Aurelia Fetch Client

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Format date and time in a Windows batch script

Next Post:

How to add some non-standard font to a website?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error