Password variable masking in logs triggers an OutOfMemoryError: Java heap space

Problem

Your builds fail due to Tasks for AWS encountering an java.lang.OutOfMemoryError: Java heap space:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 2016-04-24 22:16:08,421 ERROR [16-BAM::Deployment::Agent:pool-32-thread-1] [TaskExecutorImpl] Error occurred while running Task 'Create Deplyoment Environment' of type net.utoolity.atlassian.bamboo.tasks-for-aws:aws.cloudformation.stack. java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:3332) at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:137) at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:121) at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:445) at java.lang.StringBuffer.append(StringBuffer.java:312) at java.lang.StringBuffer.append(StringBuffer.java:97) at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:459) at java.lang.StringBuffer.append(StringBuffer.java:340) at java.util.regex.Matcher.appendReplacement(Matcher.java:890) at java.util.regex.Matcher.replaceAll(Matcher.java:955) at java.lang.String.replace(String.java:2240) at com.atlassian.bamboo.util.PasswordMaskingUtils.mask(PasswordMaskingUtils.java:107) at com.atlassian.bamboo.util.PasswordMaskingUtils.maskPossiblePasswordValues(PasswordMaskingUtils.java:163) at com.atlassian.bamboo.build.logger.interceptors.PasswordMaskingLogMutator.createMutatedLog(PasswordMaskingLogMutator.java:32) at com.atlassian.bamboo.build.logger.interceptors.PasswordMaskingLogMutator.mutate(PasswordMaskingLogMutator.java:21) at com.atlassian.bamboo.build.logger.LogMutatorStack.mutate(LogMutatorStack.java:52) at com.atlassian.bamboo.build.logger.AbstractBuildLogger.interceptAndMutate(AbstractBuildLogger.java:125) at com.atlassian.bamboo.build.logger.AbstractBuildLogger.addBuildLogEntry(AbstractBuildLogger.java:104) at com.atlassian.bamboo.build.logger.AbstractBuildLogger.addBuildLogEntry(AbstractBuildLogger.java:163) at net.utoolity.atlassian.bamboo.taws.AWSTask.createAndLogSingleVariable(AWSTask.java:375) at net.utoolity.atlassian.bamboo.taws.AWSTask.createAndLogVariables(AWSTask.java:359) at net.utoolity.atlassian.bamboo.taws.CloudFormationTask.describeSingleResource(CloudFormationTask.java:1253) at net.utoolity.atlassian.bamboo.taws.CloudFormationTask.describeResources(CloudFormationTask.java:1234) at net.utoolity.atlassian.bamboo.taws.CloudFormationTask.waitForTransitionCompletion(CloudFormationTask.java:1080) at net.utoolity.atlassian.bamboo.taws.CloudFormationTask.updateStack(CloudFormationTask.java:643) at net.utoolity.atlassian.bamboo.taws.CloudFormationTask.executeUpdate(CloudFormationTask.java:443) at net.utoolity.atlassian.bamboo.taws.CloudFormationTask.execute(CloudFormationTask.java:228) at net.utoolity.atlassian.bamboo.taws.AWSTask.execute(AWSTask.java:145) at com.atlassian.bamboo.task.TaskExecutorImpl.lambda$executeTasks$125(TaskExecutorImpl.java:273) at com.atlassian.bamboo.task.TaskExecutorImpl$$Lambda$170/1230542041.call(Unknown Source) at com.atlassian.bamboo.task.TaskExecutorImpl.executeTaskWithPrePostActions(TaskExecutorImpl.java:202) at com.atlassian.bamboo.task.TaskExecutorImpl.executeTasks(TaskExecutorImpl.java:273)

Solution

This problem is caused by an upstream bug introduced in Bamboo 5.9.1 and addressed in Bamboo 5.12.0.2:

Accordingly, you can address it by either upgrading Bamboo to a release that contains a respective fix, or by updating to Tasks for AWS 2.10.4, which provides a respective workaround (refer to https://utoolity.atlassian.net/browse/UAA-168 for details).

 

Feature flag

The workaround avoids the build log flooding by skipping the creation of variables if they are password variables (variable name contains "password", "awsSecretKey" or "passphrase"and the variable value contains only asterisks.

For the (unlikely) case that this would affect any existing build configurations, the workaround can be disabled by setting a global or plan variable utoolity.flags.disableWorkaroundForBAM17488 to true.