Broken pipe

Posted on Broken pipeError is an illegal operation performed by the user which results in the abnormal working of the program. By now, you’ve probably seen a few errors, either when compiling or running your code like Broken pipe. It can be frustrating, but they can also give you a lot of information about exactly how you can fix the problems in your code about java and spring-mvc. In this post covers the types of errors you’ll see when programming in Java, and how to fix them. Don’t pay any attention to the number of errors. Just read the first error message and work on fixing that error.

Problem :

We are currently migrating a legacy application to Jetty. And I have somehow an exception regarding a broken pipe.

  • Java 6
  • Jetty 8.1.8
  • Spring 3.2.0

I am trying to migrate a Glassfish web application to Jetty. In our testing environment we are using a load balancer and everything is working fine. Our clients are working without any problem.

WARN  [2013-04-03 13:34:28,963] com.myapp.bbb.config.MvcDefaultConfig$1: Handler execution resulted in exception
! null
! at org.eclipse.jetty.http.HttpGenerator.flushBuffer(
! at org.eclipse.jetty.http.HttpGenerator.complete(
! at org.eclipse.jetty.server.AbstractHttpConnection.completeResponse(
! at org.eclipse.jetty.server.Response.complete(
! at org.eclipse.jetty.server.Response.sendError(
! at org.eclipse.jetty.server.Response.sendError(
! at org.springframework.web.servlet.DispatcherServlet.noHandlerFound(
! at org.springframework.web.servlet.DispatcherServlet.doDispatch(
! at org.springframework.web.servlet.DispatcherServlet.doService(
! at org.springframework.web.servlet.FrameworkServlet.processRequest(
! at org.springframework.web.servlet.FrameworkServlet.doGet(
! at javax.servlet.http.HttpServlet.service(
! at org.springframework.web.servlet.FrameworkServlet.service(
! at javax.servlet.http.HttpServlet.service(
! at org.eclipse.jetty.servlet.ServletHolder.handle(
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(
! at com.magnetdigital.maggy.dropwizard.head2get.Head2GetFilter.doFilter(
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(
! at com.yammer.dropwizard.servlets.ThreadNameFilter.doFilter(
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(
! at org.eclipse.jetty.servlet.ServletHandler.doHandle(
! at org.eclipse.jetty.server.session.SessionHandler.doHandle(
! at org.eclipse.jetty.server.handler.ContextHandler.doHandle(
! at org.eclipse.jetty.servlet.ServletHandler.doScope(
! at org.eclipse.jetty.server.session.SessionHandler.doScope(
! at org.eclipse.jetty.server.handler.ContextHandler.doScope(
! at org.eclipse.jetty.server.handler.ScopedHandler.handle(
! at org.eclipse.jetty.server.handler.HandlerWrapper.handle(
! at com.yammer.metrics.jetty.InstrumentedHandler.handle(
! at org.eclipse.jetty.server.handler.GzipHandler.handle(
! at com.yammer.dropwizard.jetty.BiDiGzipHandler.handle(
! at org.eclipse.jetty.server.handler.HandlerCollection.handle(
! at org.eclipse.jetty.server.handler.HandlerWrapper.handle(
! at org.eclipse.jetty.server.Server.handle(
! at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(
! at org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(
! at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(
! at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(
! at org.eclipse.jetty.http.HttpParser.parseNext(
! at org.eclipse.jetty.http.HttpParser.parseAvailable(
! at org.eclipse.jetty.server.BlockingHttpConnection.handle(
! at org.eclipse.jetty.server.nio.BlockingChannelConnector$
! at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(
! at org.eclipse.jetty.util.thread.QueuedThreadPool$
! at
Caused by: ! Broken pipe
! at Method)
! at
! at
! at
! at
! at
! at org.eclipse.jetty.server.nio.BlockingChannelConnector$BlockingChannelEndPoint.flush(
! at org.eclipse.jetty.http.HttpGenerator.flushBuffer(
!... 44 common frames omitted

When I check the stacktrace I have seen this exceptions are triggered by always a 404 request.


  • Why am I having this exception?
  • How can I reproduce this exception at my machine locally?

Solution :

The most common reason I’ve had for a “broken pipe” is that one machine (of a pair communicating via socket) has shut down its end of the socket before communication was complete. About half of those were because the program communicating on that socket had terminated.

If the program sending bytes sends them out and immediately shuts down the socket or terminates itself, it is possible for the socket to cease functioning before the bytes have been transmitted and read.

Try putting pauses anywhere you are shutting down the socket and before you allow the program to terminate to see if that helps.

FYI: “pipe” and “socket” are terms that get used interchangeably sometimes.

I agree with @arcy, the problem is on client side, on my case it was because of nginx, let me elaborate
I am using nginx as the frontend (so I can distribute load, ssl, etc …) and using proxy_pass to forward the appropiate requests to tomcat.

There is a default value for the nginx variable proxy_read_timeout of 60s that should be enough, but on some peak moments my setup would error with the Broken pipe changing the value will help until the root cause (60s should be enough) can be fixed.

NOTE: I made a new answer so I could expand a bit more with my case (it was the only mention I found about this error on internet after looking quite a lot)

Basically, what is happening is that your user is either closing the browser tab, or is navigating away to a different page, before communication was complete. Your webserver (Jetty) generates this exception because it is unable to send the remaining bytes. null
! at org.eclipse.jetty.http.HttpGenerator.flushBuffer(
! at org.eclipse.jetty.http.HttpGenerator.complete(
! at org.eclipse.jetty.server.AbstractHttpConnection.completeResponse(

This is not an error on your application logic side. This is simply due to user behavior. There is nothing wrong in your code per se.

There are two things you may be able to do:

  1. Ignore this specific exception so that you don’t log it.
  2. Make your code more efficient/packed so that it transmits less data. (Not always an option!)

Error message suggests that the client has closed the connection while the server is still trying to write out a response.

Refer to this link for more details:

increase the response.getBufferSize()
get the buffer size and compare with the bytes you want to transfer !

You may have not set the output file.

Maybe still someone will find this answer relevant: In my case this error was due to file upload limit being smaller than uploaded file size.

Leave a Reply

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