Hi,
we are using Restlet 1.1.8 with spring on a tomcat server. We switched 
to the EncodeRepresentation with Gzip to reduce the traffic on client 
side. This works fine for most systems, but on one system the jvm 
crashes after a few minutes with client requests (ubuntu on an xen host).
The java process grows up to more than 3GB and crashes with a fatal error.

The EncodeRepresentation only calls finish() and not close() on the 
GzipOutputStream. The GzipOutputStream calls the end() method on the 
native gzip deflater at the close() method not at the finish().

A lot of other Represenations uses the ByteUtils to write the stream and 
there is close() on the steam. I put encoderOutputStream.close(); next 
to the finish at the write method of the EncodeRepresentation and the 
server runs.

Is it safe to close the stream?

I do not know why the problem only exists on the xen system. The heap 
size is the same, so the gc should work (and close the streams) similar 
to all other tomcats.

Thanks,
Felix

    @Override
    public void write(final OutputStream outputStream) throws IOException {
        if (canEncode()) {
            DeflaterOutputStream encoderOutputStream = null;

            if (encoding.equals(Encoding.GZIP)) {
                encoderOutputStream = new GZIPOutputStream(outputStream);
            } else if (encoding.equals(Encoding.DEFLATE)) {
                encoderOutputStream = new 
DeflaterOutputStream(outputStream);
            } else if (encoding.equals(Encoding.ZIP)) {
                final ZipOutputStream stream = new 
ZipOutputStream(outputStream);
                if (getWrappedRepresentation().getDownloadName() != null) {
                    stream.putNextEntry(new 
ZipEntry(getWrappedRepresentation().getDownloadName()));
                } else {
                    stream.putNextEntry(new ZipEntry("entry"));
                }

                encoderOutputStream = stream;
            } else if (encoding.equals(Encoding.IDENTITY)) {
                // Encoder unecessary for identity encoding
            }

            if (encoderOutputStream != null) {
                getWrappedRepresentation().write(encoderOutputStream);
                encoderOutputStream.finish();
                encoderOutputStream.close();
            } else {
                getWrappedRepresentation().write(outputStream);
            }
        } else {
            getWrappedRepresentation().write(outputStream);
        }
   

-- 
Felix Breske, B.Sc (FH)
Entwicklung
Email: [email protected]

Bader & Jene Software-Ingenieurbüro GmbH
Schauenburgerstraße 116
24118 Kiel

Fon: + 49.431.5 60 66 35
Fax: + 49.431.5 60 66 44
Web: www.bader-jene.de

Ust-ID Nr: DE249078452
Amtsgericht Kiel, HRB 8298

Geschäftsführer:
Dipl.-Ing. (FH) Thomas Bader
Dipl.-Ing. (FH) Andreas Jene

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2449037

Reply via email to