Sonar Scanner hangs and exits with 143 after timeout

We use SonarCloud.

  • ALM used: GitHub
  • CI system used: Jenkins
  • Scanner command used when applicable: I’d say only params without our IDs are
SONAR_SCANNER_OPTS=-Xms2G -Xmx16G
-X for debug output

We run sonar-scanner in Docker.

  • Languages of the repository: JavaScript, TypeScript
  • Error observed:
    Exit code 143 of docker container.

Project is ~1M SLOC.

Last logs in sonar-scanner container

11:06:08.262 DEBUG Cache entry created for key 'js:filemetadata:11.0.0.33655:<redacted>'
11:06:08.263 DEBUG Accepted file: <redacted>

and after that scanner lives for around 2 hours, after which it dies with 143 exit code.
issue only happens on main branch, PRs are working OK for whatever reason.

I’ve tried bumping XmX to no avail. Really no idea where to proceed because debug gave me nothing.

2 Likes

Sorry, just noted that for failing analysis we have params.

                "-Dsonar.pullrequest.branch=",
                "-Dsonar.pullrequest.key=",
                "-Dsonar.pullrequest.base="

They are empty, because we try to set them at all times for PR analysis. We also do not set a branch in any way, shape or form other than that. However, in the past things worked fine. Can this be related?

We are seeing the same issue with one of our js projects. And we don’t set these sonar.pullrequest.* parameters.

From my side i can only add that we have seen the analysis fail on a project with 15k LOC on July 9th and did have a successful analysis before on July 4th (with no changes in the code base or on the CI)

We can reproduce this issue with:

  • sonar-scanner-cli: 7.0.2
  • within a docker node:22-bookworm container

Hi,

Could you provide your debug (-Dsonar.verbose=true on the analysis command line) analysis logs, redacted as necessary?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Thx,
Ann

Hi Ann,

i have created a redacted and shortened version of the -X/verbose output that also includes the last logs as Roman has posted.

I also enabled NODE debug logs using DEBUG=* when calling the sonar-scanner. That reveals some more logs of what happens after the main sonar-scanner thread gets stuck.

sonarStuckDebug.log (70.0 KB)

Command: DEBUG=* ~/Downloads/sonar-scanner-7.1.0.4889-macosx-aarch64/bin/sonar-scanner -Dsonar.projectVersion=0.0.99 -Dsonar.token=<TOKEN> -Dsonar.verbose=true

This seems to be broken since the SonarJS release 11.0.0.33655 and we had to temporarily disable the sonar-analysis to unblock our CI jobs so I hope this gets resolved soon.

Best,
Marcel

I have been testing more things and wanted to give the update that we only see it failing if we include test files in the analysis. And the last ‘Accepted file’ before it gets stuck was always a *.test.js file

Failing configuration

sonar.sources=.
sonar.tests=.
sonar.exclusions=**/*.test.js,**/*.config.js
sonar.test.inclusions=**/*.test.js

If we don’t analyze test files the scanner doesn’t hang.

sonar.sources=.
# sonar.tests=.
sonar.exclusions=**/*.test.js,**/*.config.js
# sonar.test.inclusions=**/*.test.js

We haven’t touched this config in a while, maybe we are doing something wrong when configuring the tests sources.

Best,
Marcel

Hi all,

Thanks @pazeltma that log is very helpful.

@roman-belkov could you provide a debug log as well, please?

And in the meantime, I’ve flagged this for the experts.

 
Ann

2 Likes

Hello @roman-belkov and @pazeltma,

can you please try setting the sonar property sonar.javascript.node.maxspace=8192?

Please let me know if that helps

Cheers,
Victor

1 Like

Hi Victor,

sadly no change. I also tried with 16gb. I do see the new lines

15:01:08.147 INFO  Configured Node.js --max-old-space-size=8192.
15:01:08.147 INFO  Using embedded Node.js runtime.
...
15:01:08.845 INFO  Memory configuration: OS (36864 MB), Node.js (8240 MB).

Best,
Marcel

Hi @pazeltma,

would it be possible to access the full debug logs? Or is it a private repo and you prefer no to share all of them? in that case, would it possible to share them privately?

Thanks
Victor

can you please try setting the sonar property sonar.javascript.node.maxspace=8192 ?

Victor, we’ve had this param set in our sonar-project.properties file for ~3 years. Sorry for not indicating this earlier.

Here’s redacted sonar-project.properties:

# must be unique in a given SonarQube instance
sonar.projectKey=<company>

sonar.sources=.
sonar.tests=.

sonar.exclusions=<redacted>
sonar.inclusions=<redacted>
sonar.test.inclusions=<redacted>
sonar.test.exclusions=<redacted>
sonar.scm.exclusions.disabled=true
sonar.javascript.exclusions=''
sonar.javascript.lcov.reportPaths=backend/coverage/report/lcov.info,packages/**/coverage/report/lcov.info
sonar.javascript.node.maxspace=8192

would it be possible to access the full debug logs? Or is it a private repo and you prefer no to share all of them? in that case, would it possible to share them privately?

Not a problem for me at all to do this privately. Going through stuff for public upload would be tough.

2 Likes

Thanks @roman-belkov,

I’ll write you a PM.

1 Like

Hello @roman-belkov,

can you please remove this line from your properties?

sonar.javascript.exclusions=''

Seems it’s picking up all tsconfig files in node_modules because you are overriding the default js/ts exclusions (which actually contain that folder)

Please let me know if that helps

1 Like

Victor,

Unfortunately, removing this line from properties did not help. We’re having the same issue and the last logs are quite similar to previous fails. I’ll provide the latest logs in PM.

Hello @pazeltma and @roman-belkov,

the new release has been deployed in SonarCloud which should fix most issues with the dotnet scanner. Can you please confirm?

2 Likes

Thanks @victor.diez for coming back to our issue with this.

I re-checked and we still run into the same issue of ‘Accepted file: …’ and then stuck.

But i think I might have found the cause in our project.
We do have a directory test_helper, that is symlinked into other test directories. We usually symlink the whole directory which is then ignored by sonar-scanner (it does not show up in the code section)
But in one test directory we only symlinked a few test_helper/* files.
When I symlinked the whole test_helper directory instead the analysis went through again.

I will try to reproduce this issue with an example project.

@roman-belkov does your project use symlinked files too?

2 Likes

Sadly i have been unable to create a smaller example project to reproduce the issue.

For now we are unblocked because the full project sonar is successfully scanned again since changing the symlinked files to a symlinked directory that is ignored by sonar.

If i come across a sample project that has the same issue, i would report back.

Thanks,
Marcel

1 Like

I must apologize for this back and forth, but I realized i made an error during debugging the symlinks and it is still not working as expected.

I am still looking into it and found new clues, but i will try to have solid proof that it works/causes the issue.

Will report back if i have something.
Have a great weekend.
Marcel

1 Like

Hi @victor.diez,

i have been able to pin this issue down to one single JavaScript rule and could isolate the lines of code that trigger the issue.

The issue only appears when javascript:S2699 is enabled “Tests should include assertions”.
I have run my example and full project against the Quality Profile “Sonar way” with javascript:S2699 deactivated. With that change, the analysis goes through without issue (@roman-belkov are you able to reproduce that?).

The implementation that triggers this behavior seems to be related to process.env.VARIABLE usage in test files where supertest is used.

analyising just this file causes the analysis to get stuck:

"use strict";

// without these imports javascript:S2699 seems to be ignored. but in this example we don't need to use the imports
const superagentDefaults = require("superagent-defaults");
const supertest = require("supertest");


// this line doens't have to be in this file. it always causes an issue.
process.env.VARIABLE = 'some-token';

describe("fail", () => {
  it("should cause issues", () => {
    const test_input = process.env.OTHER_VARIABLE.substring(0, 6); // this line can use any process.env var.
  });
});

With this as special sonar properties.

sonar.sources=.
sonar.tests=.
sonar.exclusions=**/*.test.js
sonar.test.inclusions=**/*.test.js
sonar.sourceEncoding=UTF-8
sonar.coverage.exclusions=**/*.test.js

For now we might just disable the rule in our quality profile, or try to rewrite the unit tests that set process.env. variables on top of the file.

Thanks,
Marcel

2 Likes

Hello @pazeltma ,

Thank you for reporting. This will be fixed shortly. Here is a PR with the fix - JS-840 Fix handling of built-in modules in fully qualified name generation by zglicz · Pull Request #5645 · SonarSource/SonarJS · GitHub

Kind regards,

Michal

2 Likes