Addressing memory issues using traditional Azure DevOps pipeline and personally hosted build agents

We use:

  • Azure DevOps traditional pipeline definitions
  • Azure DevOps TFS for source control
  • Custom build agents
  • SonarCloud
  • C# is our main programming language
    Error:

##[error]java.lang.OutOfMemoryError: Java heap space

I’ve read different topics and different suggestions, but they are typically referring to a personally hosted SonarQube setup or .yaml based pipeline and don’t seem to work.

How should I configure the pipeline to address this “Java heap space” problem? What settings to use and where to configure? How can i make sure this will continue to be working when i move to a hosted build agent from Microsoft?

Full error:

2024-08-30T21:46:44.5050366Z ##[error]ERROR: Error in thread nodejs-stream-consumer
java.lang.OutOfMemoryError: Java heap space
2024-08-30T21:46:44.5051740Z ERROR: Error in thread nodejs-stream-consumer
2024-08-30T21:46:44.5052076Z java.lang.OutOfMemoryError: Java heap space
2024-08-30T21:46:44.5053091Z 
2024-08-30T21:46:47.2089212Z INFO: ------------------------------------------------------------------------
2024-08-30T21:46:47.2095591Z INFO: EXECUTION FAILURE
2024-08-30T21:46:47.2096318Z INFO: ------------------------------------------------------------------------
2024-08-30T21:46:47.2103010Z INFO: Total time: 28:03.005s
2024-08-30T21:46:47.2747651Z INFO: Final Memory: 97M/376M
2024-08-30T21:46:47.2748418Z INFO: ------------------------------------------------------------------------
2024-08-30T21:46:47.2752191Z ##[error]ERROR: Error during SonarScanner execution
2024-08-30T21:46:47.2752980Z ERROR: Error during SonarScanner execution
2024-08-30T21:46:47.2756580Z ##[error]java.lang.OutOfMemoryError: Java heap space
2024-08-30T21:46:47.2757184Z java.lang.OutOfMemoryError: Java heap space
2024-08-30T21:46:47.2757997Z ##[error]at org.sonar.ucfg.protobuf.UcfgProtos$AssignCall.newBuilderForType(na:4946)
2024-08-30T21:46:47.2758701Z 	at org.sonar.ucfg.protobuf.UcfgProtos$AssignCall.newBuilderForType(na:4946)
2024-08-30T21:46:47.2759567Z ##[error]at org.sonar.ucfg.protobuf.UcfgProtos$AssignCall.newBuilderForType(na:5942)
2024-08-30T21:46:47.2760762Z 	at org.sonar.ucfg.protobuf.UcfgProtos$AssignCall.newBuilderForType(na:5942)
2024-08-30T21:46:47.2761636Z ##[error]at com.google.protobuf.GeneratedMessageV3.newBuilderForType(na:3528)
2024-08-30T21:46:47.2762301Z 	at com.google.protobuf.GeneratedMessageV3.newBuilderForType(na:3528)
2024-08-30T21:46:47.2763115Z ##[error]at com.google.protobuf.SingleFieldBuilderV3.getBuilder(na:3450)
2024-08-30T21:46:47.2763763Z 	at com.google.protobuf.SingleFieldBuilderV3.getBuilder(na:3450)
2024-08-30T21:46:47.2764607Z ##[error]at org.sonar.ucfg.protobuf.UcfgProtos$Instruction$Builder.mergeFrom(na:4044)
2024-08-30T21:46:47.2765304Z 	at org.sonar.ucfg.protobuf.UcfgProtos$Instruction$Builder.mergeFrom(na:4044)
2024-08-30T21:46:47.2766633Z ##[error]at org.sonar.ucfg.protobuf.UcfgProtos$Instruction$1.K(na:6005)
	at org.sonar.ucfg.protobuf.UcfgProtos$Instruction$1.parsePartialFrom(na:6250)
	at com.google.protobuf.CodedInputStream$StreamDecoder.readMessage(na:1538)
2024-08-30T21:46:47.2767579Z 	at org.sonar.ucfg.protobuf.UcfgProtos$Instruction$1.K(na:6005)
2024-08-30T21:46:47.2767957Z 	at org.sonar.ucfg.protobuf.UcfgProtos$Instruction$1.parsePartialFrom(na:6250)
2024-08-30T21:46:47.2768360Z 	at com.google.protobuf.CodedInputStream$StreamDecoder.readMessage(na:1538)
2024-08-30T21:46:47.2769222Z ##[error]at org.sonar.ucfg.protobuf.UcfgProtos$BasicBlock$Builder.mergeFrom(na:2043)
2024-08-30T21:46:47.2769914Z 	at org.sonar.ucfg.protobuf.UcfgProtos$BasicBlock$Builder.mergeFrom(na:2043)
2024-08-30T21:46:47.2770759Z ##[error]at org.sonar.ucfg.protobuf.UcfgProtos$BasicBlock$1.I(na:5103)
2024-08-30T21:46:47.2771411Z 	at org.sonar.ucfg.protobuf.UcfgProtos$BasicBlock$1.I(na:5103)
2024-08-30T21:46:47.2772227Z ##[error]at org.sonar.ucfg.protobuf.UcfgProtos$BasicBlock$1.parsePartialFrom(na:5896)
2024-08-30T21:46:47.2772929Z 	at org.sonar.ucfg.protobuf.UcfgProtos$BasicBlock$1.parsePartialFrom(na:5896)
2024-08-30T21:46:47.2773774Z ##[error]at com.google.protobuf.CodedInputStream$StreamDecoder.readMessage(na:1538)
2024-08-30T21:46:47.2774676Z 	at com.google.protobuf.CodedInputStream$StreamDecoder.readMessage(na:1538)
2024-08-30T21:46:47.2775527Z ##[error]at org.sonar.ucfg.protobuf.UcfgProtos$UCFG$Builder.mergeFrom(na:1924)
2024-08-30T21:46:47.2776200Z 	at org.sonar.ucfg.protobuf.UcfgProtos$UCFG$Builder.mergeFrom(na:1924)
2024-08-30T21:46:47.2777001Z ##[error]at org.sonar.ucfg.protobuf.UcfgProtos$UCFG$1.L(na:1659)
2024-08-30T21:46:47.2777621Z 	at org.sonar.ucfg.protobuf.UcfgProtos$UCFG$1.L(na:1659)
2024-08-30T21:46:47.2778436Z ##[error]at org.sonar.ucfg.protobuf.UcfgProtos$UCFG$1.parsePartialFrom(na:45)
2024-08-30T21:46:47.2779145Z 	at org.sonar.ucfg.protobuf.UcfgProtos$UCFG$1.parsePartialFrom(na:45)
2024-08-30T21:46:47.2779967Z ##[error]at com.google.protobuf.AbstractParser.parsePartialFrom(na:3542)
2024-08-30T21:46:47.2780601Z 	at com.google.protobuf.AbstractParser.parsePartialFrom(na:3542)
2024-08-30T21:46:47.2781421Z ##[error]at com.google.protobuf.AbstractParser.parsePartialDelimitedFrom(na:3060)
2024-08-30T21:46:47.2782103Z 	at com.google.protobuf.AbstractParser.parsePartialDelimitedFrom(na:3060)
2024-08-30T21:46:47.2782960Z ##[error]at com.google.protobuf.AbstractParser.parseDelimitedFrom(na:3062)
2024-08-30T21:46:47.2783616Z 	at com.google.protobuf.AbstractParser.parseDelimitedFrom(na:3062)
2024-08-30T21:46:47.2784430Z ##[error]at com.google.protobuf.AbstractParser.parseDelimitedFrom(na:683)
2024-08-30T21:46:47.2785172Z 	at com.google.protobuf.AbstractParser.parseDelimitedFrom(na:683)
2024-08-30T21:46:47.2786016Z ##[error]at com.google.protobuf.AbstractParser.parseDelimitedFrom(na:1940)
2024-08-30T21:46:47.2786656Z 	at com.google.protobuf.AbstractParser.parseDelimitedFrom(na:1940)
2024-08-30T21:46:47.2787558Z ##[error]at com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(na:2884)
2024-08-30T21:46:47.2788267Z 	at com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(na:2884)
2024-08-30T21:46:47.2789100Z ##[error]at org.sonar.ucfg.protobuf.UcfgProtos$UCFG.parseDelimitedFrom(na:99)
2024-08-30T21:46:47.2789928Z 	at org.sonar.ucfg.protobuf.UcfgProtos$UCFG.parseDelimitedFrom(na:99)
2024-08-30T21:46:47.2790623Z ##[error]at com.sonar.A.D.C(na:942)
2024-08-30T21:46:47.2791237Z 	at com.sonar.A.D.C(na:942)
2024-08-30T21:46:47.2791894Z ##[error]at com.sonar.security.A.B.A(na:3399)
2024-08-30T21:46:47.2792436Z 	at com.sonar.security.A.B.A(na:3399)
2024-08-30T21:46:47.2793095Z ##[error]at com.sonar.security.E.A(na:3362)
2024-08-30T21:46:47.2793628Z 	at com.sonar.security.E.A(na:3362)
2024-08-30T21:46:47.2794352Z ##[error]at com.sonar.security.E.readUcfgs(na:1061)
2024-08-30T21:46:47.2795067Z 	at com.sonar.security.E.readUcfgs(na:1061)
2024-08-30T21:46:47.2796177Z ##[error]at com.sonar.security.E.A(na:3242)
2024-08-30T21:46:47.2796750Z 	at com.sonar.security.E.A(na:3242)
2024-08-30T21:46:47.2797262Z ##[error]at com.sonar.security.E.A(na:342)
2024-08-30T21:46:47.2797702Z 	at com.sonar.security.E.A(na:342)
2024-08-30T21:46:47.2798258Z ##[error]at com.sonar.security.E.executeChecks(na:3263)
2024-08-30T21:46:47.2798719Z 	at com.sonar.security.E.executeChecks(na:3263)
2024-08-30T21:46:47.2799272Z ##[error]at com.sonar.security.E.executeChecks(na:2918)
2024-08-30T21:46:47.2799718Z 	at com.sonar.security.E.executeChecks(na:2918)
2024-08-30T21:46:47.2800254Z ##[error]at com.sonar.security.E.execute(na:860)
2024-08-30T21:46:47.2800777Z 	at com.sonar.security.E.execute(na:860)
2024-08-30T21:46:47.2801333Z ##[error]at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:63)
2024-08-30T21:46:47.2801833Z 	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:63)
2024-08-30T21:46:47.2802274Z ##[error]ERROR:
2024-08-30T21:46:47.2802574Z ERROR: 
2024-08-30T21:46:47.3815333Z ##[error]The SonarScanner did not complete successfully

Thanks!

Hey there.

You can adjust the SONAR_SCANNER_JAVA_OPTS variable in your pipeline (see Set variables in Pipelines > Classic.

For what it’s worth, you can also simply use an analysis parameter rather than an environment variable (sonar.scanner.javaOpts)

A good starting value would be -Xmx2G.

Thank you! i will try this and let you know how it goes!

1 Like

it still failed with the same error message:

##[error]Exception in thread “HttpClient-1-SelectorManager” java.lang.OutOfMemoryError: Java heap space

Exception in thread “HttpClient-1-SelectorManager” java.lang.OutOfMemoryError: Java heap space

INFO: ------------------------------------------------------------------------

INFO: EXECUTION FAILURE

INFO: ------------------------------------------------------------------------

INFO: Total time: 29:13.153s

INFO: Final Memory: 98M/376M

INFO: ------------------------------------------------------------------------

##[error]ERROR: Error during SonarScanner execution

Is there anyway i can easily check if the settings made any difference? should i perhaps do a print out before the analyse task to print out the variables? or specify some other settings? Or some verbose logging?

If you turn on DEBUG level logging (sonar.verbose=true), you should see a message like this at the beginning of your scanner logs.

12:24:30.017 DEBUG Scanner max available memory: 2 GB

If you see this, and still face the issue… my next suggestion is to bump the memory up again, from -Xmx2G to -Xmx4G.

Thanks, we set it to -Xmx16G, which seemed to have resolve our issues at the moment. Thank you!