java.net.SocketException: Connection reset by peer, socket write error

I am getting this socket connection error in my java web application, which was working very well for long time. I did see this behaviour when I ran huge batch of database insertions/updates. Below is the java stacktrace of this error.

ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error
  1.  at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:327)
  2.  at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:293)
  3.  at org.apache.catalina.connector.Response.flushBuffer(Response.java:545)
  4.  at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:287)
  5.  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
  6.  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
  7.  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
  8.  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
  9.  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
  10.  at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
  11.  at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
  12.  at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
  13.  at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
  14.  at java.lang.Thread.run(Thread.java:595)

Usually, this kind of behaviour occurs when one of the following happens

  1. When user make a request, and suddenly browser get closed by user accidentally or due to browser crash
  2. When user make a request, and browser closes the http connection automatically due to exceeded content length size
  3. When user make a request, and presses the stop button

But surprisingly, there is one more reason which may cause this  problem. This is more unpredictable and very difficult to identify as well, that is problem with firewall.  When googled, I founded people complaining about firewall closing database connection automatically.  On top of this I am also not getting proper java exception stacktrace to track the error and fix.

To elaborate more on firewall issue, the error is more TCP/IP connection level error where database is closed by the firewall after database connection are idle for certain time or certain db connection length. Possibility is that there is a statefull firewall which is closing database connections after certain time limit. I am still in the process of identifying what could be the real problem. Once I found real probelm and solution, I will post it in here. If any one know the solutions, please post it in the comments section. Thank you.


Browse Realted Articles

    Bookmark and Share

    Leave a Reply