Bug 48726

Summary: DeployTask throws OutOfMemoryErrors when deploying large WAR files
Product: Tomcat 6 Reporter: adam <adam>
Component: Manager applicationAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: major    
Priority: P2    
Version: 6.0.24   
Target Milestone: default   
Hardware: All   
OS: All   
Attachments: patch (diffed from org/apache/catalina/ant)

Description adam 2010-02-10 22:46:18 UTC
Created attachment 24967 [details]
patch (diffed from org/apache/catalina/ant)

I consistently get OutOfMemory errors when attempting to deploy a 70 mb WAR file to Tomcat using the Deploy ant task:

java.lang.OutOfMemoryError: Java heap space
        at org.apache.catalina.ant.AbstractCatalinaTask.execute(AbstractCatalinaTask.java:262)
        at org.apache.catalina.ant.DeployTask.execute(DeployTask.java:201)
        at com.flyer.izpack.webapp.Deploy.run(Deploy.java:68)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.izforge.izpack.installer.ProcessPanelWorker$ExecutableClass.run(Unknown Source)
        at com.izforge.izpack.installer.ProcessPanelWorker$ProcessingJob.run(Unknown Source)
        at com.izforge.izpack.installer.ProcessPanelWorker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.OutOfMemoryError: Java heap space
        at java.util.Arrays.copyOf(Unknown Source)
        at java.io.ByteArrayOutputStream.write(Unknown Source)
        at sun.net.www.http.PosterOutputStream.write(Unknown Source)
        at java.io.BufferedOutputStream.write(Unknown Source)
        at org.apache.catalina.ant.AbstractCatalinaTask.execute(AbstractCatalinaTask.java:215)
        ... 10 more
--- Nested Exception ---
java.lang.OutOfMemoryError: Java heap space
        at java.util.Arrays.copyOf(Unknown Source)
        at java.io.ByteArrayOutputStream.write(Unknown Source)
        at sun.net.www.http.PosterOutputStream.write(Unknown Source)
        at java.io.BufferedOutputStream.write(Unknown Source)
        at org.apache.catalina.ant.AbstractCatalinaTask.execute(AbstractCatalinaTask.java:215)
        at org.apache.catalina.ant.DeployTask.execute(DeployTask.java:201)
        at com.flyer.izpack.webapp.Deploy.run(Deploy.java:68)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.izforge.izpack.installer.ProcessPanelWorker$ExecutableClass.run(Unknown Source)
        at com.izforge.izpack.installer.ProcessPanelWorker$ProcessingJob.run(Unknown Source)
        at com.izforge.izpack.installer.ProcessPanelWorker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

I've tracked the issue to the use of java.net.HttpURLConnection without setting the contentLength (in some cases) and not using 'fixed length streaming mode' when contentLength is available.

I'm attaching a patch that works for me with the DeployTask. I know that org.apache.catalina.ant.AbstractCatalinaTask is subclassed by many tasks, but I haven't tested all of those.

I can probably provide some code to reproduce if needed.

See also: https://issues.apache.org/bugzilla/show_bug.cgi?id=47660
Comment 1 Mark Thomas 2010-02-10 23:49:59 UTC
Thanks for the patch. I've applied it to trunk and proposed it for 6.0.x
Comment 2 Sebb 2010-02-11 01:14:02 UTC
This may be completely irrelevant in this case, but just in case, the Javadoc for HttpURLConnection has the following comment:

"When output streaming is enabled, authentication and redirection cannot be handled automatically."

[This was suggested as a solution for preventing OOM in JMeter file uploads. Not used it yet, as it would need to be optional.]
Comment 3 Mark Thomas 2010-02-22 21:11:27 UTC
This has been fixed in 6.0.x and will be included in 6.0.25 onwards. Thanks again for the patch.