SonarScanner CLI - OOM with 2 Small Python Files (~60 lines)

Hello all,

Just hoping to setup a few example applications using Sonar Scanner with GH Actions and am running into an issue when trying to analyze a very small python codebase.

SonarQube server 8.9.6
sonarsource/sonar-scanner-cli:4.7

Initial Error faced:

15:26:39.437 INFO: 0/2 files analyzed, current file: flaskExample/main.py
15:26:49.944 INFO: 0/2 files analyzed, current file: flaskExample/main.py
15:27:01.650 INFO: 0/2 files analyzed, current file: flaskExample/main.py
15:27:12.852 INFO: 0/2 files analyzed, current file: flaskExample/main.py
15:27:23.545 INFO: 0/2 files analyzed, current file: flaskExample/main.py
Exception in thread "global symbols computation progress" java.lang.OutOfMemoryError: Java heap space
	at java.base/java.util.Arrays.copyOfRange(Arrays.java:4030)
	at java.base/java.lang.StringLatin1.newString(StringLatin1.java:715)
	at java.base/java.lang.StringBuilder.toString(StringBuilder.java:452)
	at org.sonarsource.analyzer.commons.ProgressReport.run(ProgressReport.java:62)
	at java.base/java.lang.Thread.run(Thread.java:829)
15:27:43.349 INFO: ------------------------------------------------------------------------
15:27:43.749 ERROR: Error during SonarScanner execution
java.lang.OutOfMemoryError: Java heap space
15:27:43.349 INFO: EXECUTION FAILURE
	at org.sonar.sslr.internal.matchers.ParseNode.<init>(ParseNode.java:39)
15:27:43.349 INFO: ------------------------------------------------------------------------
	at org.sonar.sslr.internal.vm.Machine.createNode(Machine.java:256)
15:27:43.349 INFO: Total time: 2:40.700s
	at org.sonar.sslr.internal.vm.Instruction$RetInstruction.execute(Instruction.java:305)
15:27:43.749 INFO: Final Memory: 14M/123M
	at org.sonar.sslr.internal.vm.Machine.execute(Machine.java:162)
15:27:43.749 INFO: ------------------------------------------------------------------------
	at org.sonar.sslr.internal.vm.Machine.execute(Machine.java:105)
	at org.sonar.sslr.internal.vm.Machine.parse(Machine.java:61)
	at com.sonar.sslr.impl.Parser.parse(Parser.java:84)
	at org.sonar.python.parser.PythonParser$SslrPythonParser.parse(PythonParser.java:83)
	at org.sonar.python.parser.PythonParser.parse(PythonParser.java:49)
	at org.sonar.python.types.TypeShed.builtinSymbols(TypeShed.java:92)
	at org.sonar.python.semantic.SymbolTableBuilder$FirstPhaseVisitor.visitFileInput(SymbolTableBuilder.java:277)
	at org.sonar.python.tree.FileInputImpl.accept(FileInputImpl.java:79)
	at org.sonar.python.semantic.SymbolTableBuilder.visitFileInput(SymbolTableBuilder.java:130)
	at org.sonar.python.types.TypeShed.getModuleSymbols(TypeShed.java:247)
	at org.sonar.python.types.TypeShed.searchTypeShedForModule(TypeShed.java:203)
	at org.sonar.python.types.TypeShed.symbolsForModule(TypeShed.java:163)
	at org.sonar.python.types.TypeShed.symbolWithFQN(TypeShed.java:172)
	at org.sonar.python.semantic.Scope.addImportedSymbol(Scope.java:201)
	at org.sonar.python.semantic.SymbolTableBuilder$FirstPhaseVisitor.lambda$createImportedNames$0(SymbolTableBuilder.java:395)
	at org.sonar.python.semantic.SymbolTableBuilder$FirstPhaseVisitor$$Lambda$1050/0x000000010094bc40.accept(Unknown Source)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.sonar.python.semantic.SymbolTableBuilder$FirstPhaseVisitor.createImportedNames(SymbolTableBuilder.java:383)
	at org.sonar.python.semantic.SymbolTableBuilder$FirstPhaseVisitor.visitImportFrom(SymbolTableBuilder.java:377)
	at org.sonar.python.tree.ImportFromImpl.accept(ImportFromImpl.java:120)
	at org.sonar.plugins.python.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:33)
	at org.sonar.plugins.python.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:40)
	at org.sonar.plugins.python.api.tree.BaseTreeVisitor.visitStatementList(BaseTreeVisitor.java:52)
	at org.sonar.python.tree.StatementListImpl.accept(StatementListImpl.java:46)
	at org.sonar.plugins.python.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:33)
	at org.sonar.plugins.python.api.tree.BaseTreeVisitor.visitFileInput(BaseTreeVisitor.java:47)
	at org.sonar.python.semantic.SymbolTableBuilder$FirstPhaseVisitor.visitFileInput(SymbolTableBuilder.java:282)
	at org.sonar.python.tree.FileInputImpl.accept(FileInputImpl.java:79)

I attempted to bump the memory to the max request of the underlying container with the following:

SONAR_SCANNER_OPTS: -Xmx512m

This gets to the same point but errors out with the following:

14:46:09.570 DEBUG: 'flaskExample/main.py' generated metadata with charset 'UTF-8'
14:46:19.564 INFO: 0/2 files analyzed, current file: flaskExample/main.py
14:46:29.564 INFO: 0/2 files analyzed, current file: flaskExample/main.py
14:46:39.657 INFO: 0/2 files analyzed, current file: flaskExample/main.py
time="2022-08-01T14:46:42Z" level=error msg="error waiting for container: unexpected EOF"
read tcp 127.0.0.1:1234->127.0.0.1:5678: read: connection reset by peer

Have set the sonar.sources folder to be more specific and have also tried using sonar.inclusions=**/*.py.

Any ideas on why you’d need more than 512m to analyze 60 lines of Python? Or are there other troubleshooting steps I can take to see why this would be happening?

Same set up is working just fine with a small Node.JS project.

Hey there.

Can you include the file, so we can try and reproduce it on our end?