Forum Stats

  • 3,837,920 Users
  • 2,262,309 Discussions


Glassfish 4 HeapBuffer has already been disposed

Glassfish 4.0 Build 89


I have a servlet to provide images from our filestore. If an image is requested bigger than ~1.7Mb it is either truncated, corrupted, or missing. The status code of the request is always 200 OK.

The following stack trace occurs:

[2017-02-17T10:10:08.528+0000] [glassfish 4.0] [WARNING] [] [org.glassfish.grizzly.ProcessorExecutor] [tid: _ThreadID=45 _ThreadName=jk-connector(3)] [timeMillis: 1487326208528] [levelValue: 900] [[  Error during Processor execution. Connection=TCPNIOConnection{localSocketAddress={/}, peerSocketAddress={/}} ioEvent=WRITE [email protected]2d4f3a4java.lang.IllegalStateException: HeapBuffer has already been disposed    at org.glassfish.grizzly.memory.HeapBuffer.checkDispose(    at org.glassfish.grizzly.memory.HeapBuffer.position(    at org.glassfish.grizzly.memory.BuffersBuffer.get(    at org.glassfish.grizzly.memory.BuffersBuffer.get(    at org.glassfish.grizzly.memory.BuffersBuffer.get(    at org.glassfish.grizzly.memory.BuffersBuffer.get(    at org.glassfish.grizzly.memory.BuffersBuffer.get(    at org.glassfish.grizzly.nio.transport.TCPNIOAsyncQueueWriter.fillByteBuffer(    at org.glassfish.grizzly.nio.transport.TCPNIOAsyncQueueWriter.writeComposite0(    at org.glassfish.grizzly.nio.transport.TCPNIOAsyncQueueWriter.write0(    at org.glassfish.grizzly.nio.AbstractNIOAsyncQueueWriter.processAsync(    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(    at org.glassfish.grizzly.ProcessorExecutor.execute(    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(    at org.glassfish.grizzly.threadpool.AbstractThreadPool$    at]]

Sample code snippet:

        //String pathJpg derived from database call (not shown here)        File file = new File(pathJpg);        String mime = "image/jpeg";                response.setContentLengthLong(file.length());        response.setContentType(mime);        FileInputStream in = new FileInputStream(file);        try {            byte[] buf = new byte[1024];            int count;            while ((count = >= 0) {                response.getOutputStream().write(buf);            }        }        finally {            in.close();        }

Calls to this servlet are being done via dynamically altering the src tag of an image upon clicking a button

Others have previous reported similar issues and it was registered as a bug, but it appears unresolved:

Occurs irrespective of our Byte Buffer Type (Default DIRECT, but occurs with HEAP also) and irrespective of byte buffer sizes, chunking mode, compression or similar.

I have also tried replacing the grizzly jars in the Glassfish mq/lib folder with the latest versions - this also made no difference

I'm out of ideas, so any suggestions would be appreciated

This discussion has been closed.