Deployment using Bamboo Tomcat deploy and Tomcat restart task plugins causes out of memory exception
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
The steps outlined on this article are provided AS-IS. This means we've had reports of them working for some customers — under certain circumstances — yet are not officially supported, nor can we guarantee they'll work for your specific scenario.
You may follow through and validate them on your own non-prod environments prior to production, or fall back to supported alternatives if they don't work out.
We also invite you to contact our Community for matters that are outside Atlassian's scope of support!
Deploying a Tomcat-based application using Bamboo Tomcat deploy and Tomcat restart task plugins causes an out-of-memory exception in the application where the deployment is happening.
Environment
The issue is seen on Bamboo 8.2.4 + Java 7-based external application where deployment was done. Although this issue can be seen on any supported Bamboo version, a few parameters explained below on the external application side are applicable only for Java 7 and below versions.
Diagnosis
While using the Bamboo Tomcat deploy and Tomcat restart task plugins to deploy a Tomcat-based external application, an out-of-memory exception was seen in the external application logs. Below are the error snippets from Bamboo and the external application.
Bamboo deployment logs
Trying to retrieve Tomcat details from Found Tomcat Version: [Apache Tomcat/8.5.69]05-Oct-2022 14:58:53Confirmed Tomcat version: [Apache Tomcat/8.5.69]Could not reload application: Connection resetFinished task 'Tomcat deploy' with result: Error
External application logs
SEVERE [http-nio-18091-exec-37] org.apache.tomcat.util.modeler.BaseModelMBean.invoke Exception invoking method check
java.lang.OutOfMemoryError: PermGen space
Cause
The Out of Memory exception as per the error message is coming only on the PermGen space and not the whole Heap, see the structure of heap memory below, Perm space is used to keep informations for loaded classes and few other advanced features like String Pool(for highly optimized string equality testing), which usually get created by String.intern() methods.
As the application(number of classes) will grow this space shall get filled quickly, since the garbage collection on this Space is not much effective to clean up as required, the application quickly get Out of Memory : perm gen space error. After then, no application shall run on that machine effectively even after having a huge empty JVM.
Solution
The first step is to increase the Perm Gen space by using the below parameter on the external application side
-XX:PermSize=512m -XX:MaxPermSize=1024m
ℹ️ Please replace the values accordingly as applicable for your instance.
The next steps is to pass the below 2 flags to the external application JVM
-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled
Was this helpful?