camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject camel git commit: Fix: OutOfMemoryErrors due to not explicit closed Deflater
Date Thu, 29 Sep 2016 06:26:11 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.17.x 8b39c2b23 -> 7dcdb0a7c


Fix: OutOfMemoryErrors due to not explicit closed Deflater

The Deflater usage in this class might cause OutOfMemoryErrors. These will arise in high-load
+ high-ram-jvm scenarios as the GC cannot monitor the Deflater's internal native buffer.

"""
Caused by: java.lang.OutOfMemoryError: null
                at java.util.zip.Deflater.init(Native Method)
                at java.util.zip.Deflater.<init>(Deflater.java:171)
                at java.util.zip.Deflater.<init>(Deflater.java:180)
                at org.apache.camel.impl.ZipDataFormat.marshal(ZipDataFormat.java:58)
                at org.apache.camel.processor.MarshalProcessor.process(MarshalProcessor.java:81)
                ... 33 common frames omitted
"""


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7dcdb0a7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7dcdb0a7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7dcdb0a7

Branch: refs/heads/camel-2.17.x
Commit: 7dcdb0a7ca801a0eb7de46394f2cb28b5a8a3d0e
Parents: 8b39c2b
Author: Andreas <andmoos@users.noreply.github.com>
Authored: Wed Sep 28 15:13:14 2016 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Sep 29 08:25:46 2016 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/camel/impl/ZipDataFormat.java | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7dcdb0a7/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java b/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
index 68ee7be..4bd00ad 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
@@ -59,13 +59,22 @@ public class ZipDataFormat extends org.apache.camel.support.ServiceSupport
imple
 
     public void marshal(final Exchange exchange, final Object graph, final OutputStream stream)
throws Exception {
         // ask for a mandatory type conversion to avoid a possible NPE beforehand as we do
copy from the InputStream
-        InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class,
exchange, graph);
+        final InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class,
exchange, graph);
 
-        DeflaterOutputStream zipOutput = new DeflaterOutputStream(stream, new Deflater(compressionLevel));
+        final Deflater deflater = new Deflater(compressionLevel);
+        final DeflaterOutputStream zipOutput = new DeflaterOutputStream(stream, new Deflater(compressionLevel));
         try {
             IOHelper.copy(is, zipOutput);
         } finally {
             IOHelper.close(is, zipOutput);
+            
+            /*
+            * As we create the Deflater our self and do not use the stream default
+            * (see {@link java.util.zip.DeflaterOutputStream#usesDefaultDeflater})
+            * we need to close the Deflater to not risk a OutOfMemoryException
+            * in native code parts (see {@link java.util.zip.Deflater#end})
+            */
+            deflater.end();
         }
     }
 


Mime
View raw message