forcedotcom / sfdx-scanner

MIT License
214 stars 49 forks source link

When running DFA scan on windows machine getting GC overhead limit exceeded #1452

Closed saurabhdxtmcim closed 5 months ago

saurabhdxtmcim commented 5 months ago

Even when trying to run the scanner for a single file with command: sf scanner run dfa --category Security --sfgejvmargs -Xmx20g --target ".\force-app\main\default\classes\abc.cls" --projectdir ".\force-app\" --format csv --outfile "CodeAnalyzerDFA.csv"

Getting this error.

apex.jorje.parser.impl.BaseApexLexer dedupe INFO: Deduped array ApexLexer.DFA22_transition. Found 7075528 shorts which is 13MB not including array overhead. Removed 6418975 shorts which is 12MB not counting array overhead. Took 9 ms. Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded at org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal.property(GraphTraversal.java:2245) at org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal.property(GraphTraversal.java:2274) at com.salesforce.graph.build.GremlinVertexUtil.addProperty(GremlinVertexUtil.java:77) at com.salesforce.graph.build.AbstractApexVertexBuilder.addProperties(AbstractApexVertexBuilder.java:192) at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:56) at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:125) at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:125) at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:125) at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:125) at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:125) at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:125) at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:35) at com.salesforce.graph.build.CustomerApexVertexBuilder.build(CustomerApexVertexBuilder.java:21) at com.salesforce.graph.build.Util.buildGraph(Util.java:39) at com.salesforce.graph.ops.GraphUtil.loadSourceFolders(GraphUtil.java:170) at com.salesforce.Main$Dependencies.loadSourceFoldersToGraph(Main.java:247) at com.salesforce.Main.execute(Main.java:150) at com.salesforce.Main.process(Main.java:100) at com.salesforce.Main.main(Main.java:68)

saurabhdxtmcim commented 5 months ago

tried sf scanner run dfa --category Security --sfgejvmargs -Xmx5g --target ".\force-app\main\default\classes\filename.cls" --projectdir ".\force-app\" --format csv --outfile "CodeAnalyzerDFA.csv" --pathexplimit -1 --rule-thread-count 2 --rule-thread-timeout 300000

Still same error:

Apr 30, 2024 10:06:47 PM apex.jorje.parser.impl.BaseApexLexer dedupe INFO: Deduped array ApexLexer.DFA22_transition. Found 7075528 shorts which is 13MB not including array overhead. Removed 6418975 shorts which is 12MB not counting array overhead. Took 37 ms. Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded at java.util.HashMap.resize(Unknown Source) at java.util.HashMap.putVal(Unknown Source) at java.util.HashMap.put(Unknown Source) at org.apache.tinkerpop.gremlin.process.traversal.step.util.Parameters.set(Parameters.java:210) at org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.AddPropertyStep.(AddPropertyStep.java:59) at org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal.property(GraphTraversal.java:2245) at org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal.property(GraphTraversal.java:2274) at com.salesforce.graph.build.GremlinVertexUtil.addProperty(GremlinVertexUtil.java:77) at com.salesforce.graph.build.AbstractApexVertexBuilder.addProperties(AbstractApexVertexBuilder.java:192) at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:100) at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:125) at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:125) at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:125) at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:125) at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:125) at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:35) at com.salesforce.graph.build.CustomerApexVertexBuilder.build(CustomerApexVertexBuilder.java:21) at com.salesforce.graph.build.Util.buildGraph(Util.java:39) at com.salesforce.graph.ops.GraphUtil.loadSourceFolders(GraphUtil.java:170) at com.salesforce.Main$Dependencies.loadSourceFoldersToGraph(Main.java:247) at com.salesforce.Main.execute(Main.java:150) at com.salesforce.Main.process(Main.java:100) at com.salesforce.Main.main(Main.java:68)

saurabhdxtmcim commented 5 months ago

sfge.log has nothing just list of files like this: 2024-04-30 22:25:26 INFO GraphUtil:207 - Loading file. path=** file path ..........

Nothing else

jfeingold35 commented 5 months ago

@saurabhdxtmcim , what version of the scanner are you using? We just put out v4.1 today, so if you're not using that we recommend upgrading to it, as it's possible that the error is fixed.

saurabhdxtmcim commented 5 months ago

@jfeingold35 going to try that, and will update this thread, thanks for the quick response.

saurabhdxtmcim commented 5 months ago

@jfeingold35 Installed v4.1 but now I am getting: Error (1): Java version 5 isn't supported. Install Java 11 or later.

tried with java version 11, 17, 22 with change in the config.json: "javaHome": "C:\Program Files\Java\jdk-11" getting same error. May be I am missing something, will try it again tomorrow and keep you posted.

stephen-carter-at-sf commented 5 months ago

Can you try deleting the "javaHome" field alltogether and then try again. That java home path looks trimmed.

If that doesn't work, please share the following:

saurabhdxtmcim commented 5 months ago

Java -version: Picked up _JAVA_OPTIONS: -Xmx5g java version "17.0.11" 2024-04-16 LTS Java(TM) SE Runtime Environment (build 17.0.11+7-LTS-207)

sf --version » Warning: @salesforce/cli update available from 2.26.10 to 2.38.7. @salesforce/cli/2.26.10 win32-x86 node-v20.10.0

sf plugins » Warning: @salesforce/cli update available from 2.26.10 to 2.38.7. @salesforce/sfdx-scanner 4.1.0 (latest-beta) texei-sfdx-plugin 2.2.4

Uninstalled JIT Plugins: community 3.0.14 custom-metadata 3.1.5 dev 2.1.8 devops-center 1.2.5 env 3.0.16 functions 1.22.11 signups 2.0.17 @salesforce/sfdx-plugin-lwc-test 1.1.1

Command: sf scanner run dfa --category Security --sfgejvmargs -Xmx5g --target ".\force-app\main\default\classes\filename.cls" --projectdir ".\force-app\" --format csv --outfile "CodeAnalyzerDFA.csv" --pathexplimit -1 --rule-thread-count 2 --rule-thread-timeout 300000

Output: Warning: @salesforce/cli update available from 2.26.10 to 2.38.7. » Warning: Plugin @salesforce/sfdx-scanner (4.1.0) differs from the version specified by sf (3.20.0) Warning: We're continually improving Salesforce Code Analyzer. Tell us what you think! Give feedback at https://research.net/r/SalesforceCA Error (1): Java version 5 isn't supported. Install Java 11 or later. If the problem persists, please manually add a 'javaHome' property to your C:\Users\Saurabh Dixit\.sfdx-scanner\Config.json file, referencing your Java home directory.

saurabhdxtmcim commented 5 months ago

output was same even after deleting JAVA_HOME from the config

Just so you know I have windows machine, not mac.

saurabhdxtmcim commented 5 months ago

updated cli to latest version and java to JDK22 still same issue, i.e. We're continually improving Salesforce Code Analyzer. Tell us what you think! Give feedback at https://research.net/r/SalesforceCA Error (1): Java version 5 isn't supported. Install Java 11 or later. If the problem persists, please manually add a 'javaHome' property to your C:\Users\Saurabh Dixit\.sfdx-scanner\Config.json file, referencing your Java home directory. cli: @salesforce/cli/2.38.7 win32-x86 node-v20.12.2

stephen-carter-at-sf commented 5 months ago

Is Picked up _JAVA_OPTIONS: -Xmx5g really a part of the output when you do java --version?

If so, then i think it's because when we do a validation of which version you have... it is seeing the 5 inside of the Xmx5g before seeing the next line. That is, our regular expression to find java version might be not strict enough.

saurabhdxtmcim commented 5 months ago

yeah something like PS C:\Users\Saurabh Dixit> java -version Picked up _JAVA_OPTIONS: -Xmx5g java version "22.0.1" 2024-04-16 Java(TM) SE Runtime Environment (build 22.0.1+8-16) Java HotSpot(TM) 64-Bit Server VM (build 22.0.1+8-16, mixed mode, sharing) PS C:\Users\Saurabh Dixit>

goint to remove that environment variable then run it again

saurabhdxtmcim commented 5 months ago

@stephen-carter-at-sf I think you are right, I tried so many things, and I think it would work, going to run the scanner and will let you know. Thanks a ton, really appreciate the help.

stephen-carter-at-sf commented 5 months ago

You bet.

Internally i'll create a bug work item so our regex patter written here https://github.com/forcedotcom/sfdx-scanner/blob/9c827822bd09bcc5e043e318b2eb5d7d286cd300/src/lib/JreSetupManager.ts#L126 doesn't fumble in cases like these. So I'm going to leave this issue open until we get that fixed.

git2gus[bot] commented 5 months ago

This issue has been linked to a new work item: W-15655233

stephen-carter-at-sf commented 5 months ago

Actually I'm going to create a new issue for this to associate to a different internal work item other than W-15655233 since this issue is really about the out of memory error. I'll leave this issue open. @saurabhdxtmcim If you no longer get the out of memory issue (and have increased your run timeout limit high enough for it to finish)... if it finishes successfully for you then please close this issue.

Created https://github.com/forcedotcom/sfdx-scanner/issues/1453

saurabhdxtmcim commented 5 months ago

Finally: Java22 and cli update to 64bit with scanner latest and then resetting _JAVA_OPTIONS: -Xmx5g env variable did the trick. Thanks a lot @stephen-carter-at-sf for pointing it out, thanks @jfeingold35 for looking into the issue. Really appreciate the help.

saurabhdxtmcim commented 5 months ago

@stephen-carter-at-sf it is working for me now, Thanks a lot for the help. I am going to close this issue.