org.mortbay.jetty.EofException gets thrown when writing to response
Asked Answered
B

2

6

I am using jetty 6.1.23 within eclipse RAP (Rich Ajax Platform 1.3.2) and Java version 1.5. I am sending a PNG image to the browser. These are pieces of code that are causing trouble:

server side:

response.setContentType(application.getMimeType(".png"));
response.setContentLength(outputSize);
response.setHeader("Cache-Control", "no-cache"); 
response.setDateHeader("Expires", 0);
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Max-Age", 0); 
ServletOutputStream servletoutputstream = response.getOutputStream();

servletoutputstream.write(imageBytes); // this throws EofException

servletoutputstream.flush();

client side:

<img src="path to the servlet that is loading the image">

The thing that's weird is that this problem does not happen all the time. It happens intermittently after we moved to production. There were no problems in our test environment. The only difference between production and our test environment is that in production environment, users are far away from our servers, while in the test environment, they are very close.

When the exception gets thrown, image does not get displayed at all at the client's browser end! What is going on? What can I do to fix it or at least have a workaround?

This is the full exception trace (I highlighted key exceptions):

08 Feb 2012 11:49:08,955 ERROR [1584291438@qtp-2135195460-260] plugin.sda - 
org.mortbay.jetty.EofException
    at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:789)
    at org.mortbay.jetty.AbstractGenerator$Output.flush(AbstractGenerator.java:568)
    at org.mortbay.jetty.HttpConnection$Output.flush(HttpConnection.java:1006)
    at org.mortbay.jetty.AbstractGenerator$Output.write(AbstractGenerator.java:650)
    at org.mortbay.jetty.AbstractGenerator$Output.write(AbstractGenerator.java:590)
    at com.scotiabank.ebss.common.viewer.util.ViewerUtil.sendBytes(ViewerUtil.java:533)
    at com.scotiabank.ebss.common.viewer.servlets.ViewerServlet.doGet(ViewerServlet.java:242)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.eclipse.equinox.http.registry.internal.ServletManager$ServletWrapper.service(ServletManager.java:180)
    at org.eclipse.equinox.http.servlet.internal.ServletRegistration.service(ServletRegistration.java:61)
    at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:126)
    at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:60)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.eclipse.equinox.http.jetty.internal.HttpServerManager$InternalHttpServiceServlet.service(HttpServerManager.java:318)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:924)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.io.IOException: Broken pipe
    at sun.nio.ch.FileDispatcher.writev0(Native Method)
    at sun.nio.ch.SocketDispatcher.writev(SocketDispatcher.java:61)
    at sun.nio.ch.IOUtil.write(IOUtil.java:192)
    at sun.nio.ch.SocketChannelImpl.write0(SocketChannelImpl.java:393)
    at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:416)
    at java.nio.channels.SocketChannel.write(SocketChannel.java:375)
    at org.mortbay.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:232)
    at org.mortbay.io.nio.SelectChannelEndPoint.flush(SelectChannelEndPoint.java:211)
    at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:712)
    ... 27 more
Bellbella answered 9/2, 2012 at 4:32 Comment(1)
The exception is illiterate. The actual problem is the broken pipe, which has nothing whatsover to do with EOF.Moil
M
3

The problem appears to be network related, and has little-to-nothing to do with Jetty.

You are attempting to write an amount of data to a network socket that has been closed at the other end. That is what the Broken pipe exception means.

You need to work out why the HTTP connection is closing unexpectedly. It's possible that the cause has something to do with Jetty, but I strongly suspect not.

Muchness answered 9/2, 2012 at 11:6 Comment(0)
E
1

Check request/response size limits. Try do download smaller image <4k.

Epstein answered 9/2, 2012 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.