Can't serve large data using the Websphere Application Server

RokL picture RokL · Mar 4, 2013 · Viewed 9.5k times · Source

I wrote the simplest Servlet possible for serving a stream of data (in the test case it's a 14GB text file) to the client:

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("application/octet-stream");
    resp.setContentLength(-1);
    InputStream is = null;
    try {
        OutputStream os = resp.getOutputStream();
        int unitsTransferred = -1;
        byte[] buf = new byte[65536];
        is = new FileInputStream("D:/largetext2.txt");
        while ((unitsTransferred = is.read(buf)) != -1) {
            os.write(buf, 0, unitsTransferred);
            //os.flush();
        }
    } catch (Throwable e) {
        e.printStackTrace();
    } finally {
        try {
            is.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        try {
            resp.getOutputStream().close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

So you just make a simple get request. I tried making GET request to this servlet from a java client using URLConnection and from Chrome browser. Both cases manage to download randomly from 1 MB to 90 MB then the downloading stalls, while, even after the client has stalled, the Private Bytes of the java.exe process of the WAS server keeps going up (from 300 MB to 950 MB) then the server spits out the following stack trace:

com.ibm.wsspi.webcontainer.ClosedConnectionException: OutputStream encountered error during write
at  com.ibm.ws.webcontainer.channel.WCCByteBufferOutputStream.write(WCCByteBufferOutputStream.java:106)
at com.ibm.ws.webcontainer.srt.SRTOutputStream.write(SRTOutputStream.java:97)
at com.ibm.wsspi.webcontainer.util.BufferedServletOutputStream.writeOut(BufferedServletOutputStream.java:569)
at com.ibm.wsspi.webcontainer.util.BufferedServletOutputStream.write(BufferedServletOutputStream.java:374)
at si.test.kryo.MyServlet.doGet(MyServlet.java:60)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1663)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:939)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:179)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:864)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604)

Caused by: java.io.IOException: Async IO operation failed (2), reason: RC: 64 The specified network name is no longer available.

at com.ibm.io.async.AsyncLibrary$IOExceptionCache.<init>(AsyncLibrary.java:891)
at com.ibm.io.async.AsyncLibrary$IOExceptionCache.get(AsyncLibrary.java:904)
at com.ibm.io.async.AsyncLibrary.getIOException(AsyncLibrary.java:918)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:213)
... 3 more

Java client just stays blocked in a read call, while Chrome keeps the download alive, oblivious to the fact that server aborted the whole thing. So either there's some weird timeout going on or there's a problem with the IBM servlet container.

Can someone help me with this?

Answer