Java heap space and sonarqube-scan-action@v3.0.0

Hi,

SonarQube: 10.6, Scanner: sonarqube-scan-action@v3.0.0
Deployment method: Helm
Issue: Scanning large projects

After upgrading from SonarQube 10.1 to 10.6, I also had to upgrade sonarqube-scan-action from v1.2.0 to v2.0.0 and above. After this upgrade, a large project started encountering an error during the scan stage of the workflow:

- name: SonarQube Scan
  uses: sonarsource/sonarqube-scan-action@v3.0.0
  with:
    args: >
      -Dsonar.verbose=true
      -Dsonar.sourceEncoding=UTF-8
      -Dsonar.javascript.node.maxspace=8192
  continue-on-error: false
  env:
    SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
    SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }}
    SONAR_SCANNER_JAVA_OPTS: "-Xmx4096m"

This produces the following error:

2024-09-27T08:48:16.2126006Z 08:48:16.211 INFO  Hit the cache for 0 out of 0
2024-09-27T08:48:16.2138630Z 08:48:16.213 INFO  Miss the cache for 0 out of 0
2024-09-27T08:48:16.2203637Z 08:48:16.220 DEBUG Shutting down the worker
2024-09-27T08:48:16.2214783Z 08:48:16.221 INFO  Rule | Time (ms) | Relative
2024-09-27T08:48:16.2215965Z 08:48:16.221 INFO  :----|----------:|--------:
2024-09-27T08:48:16.2329522Z 08:48:16.232 DEBUG The worker thread exited with code 0
2024-09-27T08:48:16.2340327Z 08:48:16.233 DEBUG The bridge server shut down
2024-09-27T08:48:16.2344273Z 08:48:16.234 INFO  Rule | Time (ms) | Relative
2024-09-27T08:48:16.2345401Z 08:48:16.234 INFO  :----|----------:|--------:
2024-09-27T08:48:16.7197541Z 08:48:16.718 ERROR [stderr] Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
2024-09-27T08:48:16.7200161Z 08:48:16.719 ERROR [stderr] 	at java.base/java.io.File.listFiles(Unknown Source)
2024-09-27T08:48:16.7203395Z 08:48:16.719 ERROR [stderr] 	at org.sonar.plugins.javascript.bridge.TsConfigProvider$LookupTsConfigProvider.tsconfigs(TsConfigProvider.java:176)
2024-09-27T08:48:16.7206819Z 08:48:16.719 ERROR [stderr] 	at org.sonar.plugins.javascript.bridge.TsConfigProvider.tsconfigs(TsConfigProvider.java:94)
2024-09-27T08:48:16.7209985Z 08:48:16.719 ERROR [stderr] 	at org.sonar.plugins.javascript.bridge.TsConfigProvider.getTsConfigs(TsConfigProvider.java:89)
2024-09-27T08:48:16.7213015Z 08:48:16.719 ERROR [stderr] 	at org.sonar.plugins.javascript.bridge.JsTsSensor.analyzeFiles(JsTsSensor.java:104)
2024-09-27T08:48:16.7216046Z 08:48:16.719 ERROR [stderr] 	at org.sonar.plugins.javascript.bridge.AbstractBridgeSensor.execute(AbstractBridgeSensor.java:74)
2024-09-27T08:48:16.7219500Z 08:48:16.719 ERROR [stderr] 	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)

In total, 1,543 files are indexed. If I apply the exclusion patterns **/.ts and **/.js, the number of indexed files drops to 1,265, and the scan completes successfully.

Am I missing some important configuration related to the JVM or the Node.js Bridge Server?

Full logs:
scannerlogs.log (85.4 KB)

Hi @IuriGarcia,

this looks like a problem on our side, although I am surprised because we haven’t changed anything in this part of the code in a while.

Do you get the error consistently for each analysis? Could you try to run with a higher memory setting for the JVM -Xmx? I would try to double the max heap size.

Which Java version do you use? Do you have any symlinks in the dir structure of the analyzed project?

The issue looks similar to the one reported recently here Package.json causing Java heap space error - #6 by hus90

Hello, @saberduck !

Yes, I consistently encountered the error. However, I discovered a workaround that prevents the issue, though I can’t fully explain why it works just yet. Even with -Xmx32768m set, the error still occurred.

Oh, and yes, I have 3 symlinks right under /docroot.

Regarding the Java version, here’s the version installed in the Docker image used by the action sonarqube-scan-action@v3.0.0:

$ docker run -ti --rm sonarsource/sonar-scanner-cli:11.1 bash
bash-5.2$ java --version
openjdk 17.0.12 2024-07-16 LTS
OpenJDK Runtime Environment Corretto-17.0.12.7.1 (build 17.0.12+7-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.12.7.1 (build 17.0.12+7-LTS, mixed mode, sharing)

The error stopped occurring only after I added sonar.typescript.tsconfigPaths=**/tsconfig.json,**/tsconfig.*.json to sonar-project.properties.

By the way, I saw the issue you mentioned and I’ll check it out. Not sure when I’ll get back to you, but I’ll reply as soon as I can.

There is not much on the other issue, I will investigate this next week, as there is definitely something fishy

Hey @IuriGarcia

Sorry to come back to this late!

We recently released SonarQube v2025.1 LTA – it includes a few improvements around TsConfigProvider. Could you see if the issue can still be reproduced on this version?

If so, I promise we’ll route this to the right team.