Skip to content

Commit

Permalink
🐛 Set xmx value on JVM to avoid OOMKilled (#388)
Browse files Browse the repository at this point in the history
Fixes #340 
Fixes #386

---------

Signed-off-by: Pranav Gaikwad <[email protected]>
  • Loading branch information
pranavgaikwad authored Oct 30, 2023
1 parent ec501b3 commit 9369083
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions docs/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Here's an example config for `java` provider that is currently in-tree and does
"package1.test",
"package2.test"
],
"jvmMaxMem": "2048m",
}
}
]
Expand All @@ -105,6 +106,8 @@ The `java` provider also takes following options in `providerSpecificConfig`:

* `excludePackages`: List of dependency packages on which to add exclude label.

* `jvmMaxMem`: Max memory for JVM, value is passed as-is using `-Xmx` option. _Note that the default `-Xms` value set on JVM is `1G`, therefore, `jvmMaxMem` value less than `1G` has no effect_

#### Builtin Provider

The `builtin` provider is configured by default. To override the default config, a new config can be added to provider settings file:
Expand Down
4 changes: 2 additions & 2 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (r *ruleEngine) filterRules(ruleSets []RuleSet, selectors ...RuleSelector)
// skip rule when doesn't match any selector
if !matchesAllSelectors(rule.RuleMeta, selectors...) {
mapRuleSets[ruleSet.Name].Skipped = append(mapRuleSets[ruleSet.Name].Skipped, rule.RuleID)
r.logger.Info("one or more selectors did not match for rule, skipping", "rule", rule.RuleMeta)
r.logger.V(5).Info("one or more selectors did not match for rule, skipping", "ruleID", rule.RuleID)
continue
}

Expand Down Expand Up @@ -425,7 +425,7 @@ func (r *ruleEngine) createViolation(ctx context.Context, conditionResponse Cond
for scanner.Scan() {
if incident.LineNumber != nil && strings.HasPrefix(strings.TrimSpace(scanner.Text()), fmt.Sprintf("%v", *incident.LineNumber)) {
originalCodeSnip = strings.TrimSpace(re.ReplaceAllString(scanner.Text(), "$2"))
r.logger.Info("found orignalCodeSnip", "lineNuber", incident.LineNumber, "orignal", originalCodeSnip)
r.logger.V(5).Info("found originalCodeSnip", "lineNuber", incident.LineNumber, "original", originalCodeSnip)
break
}
}
Expand Down
10 changes: 8 additions & 2 deletions provider/internal/java/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
BUNDLES_INIT_OPTION = "bundles"
WORKSPACE_INIT_OPTION = "workspace"
MVN_SETTINGS_FILE_INIT_OPTION = "mavenSettingsFile"
JVM_MAX_MEM_INIT_OPTION = "jvmMaxMem"
)

// Rule Location to location that the bundle understands
Expand Down Expand Up @@ -244,13 +245,18 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
os.Setenv(k, v)
}

cmd := exec.CommandContext(ctx, lspServerPath,
args := []string{
"-Djava.net.useSystemProxies=true",
"-configuration",
"./",
"-data",
workspace,
)
}
if val, ok := config.ProviderSpecificConfig[JVM_MAX_MEM_INIT_OPTION].(string); ok && val != "" {
args = append(args, fmt.Sprintf("-Xmx%s", val))
}

cmd := exec.CommandContext(ctx, lspServerPath, args...)
stdin, err := cmd.StdinPipe()
if err != nil {
cancelFunc()
Expand Down
2 changes: 1 addition & 1 deletion provider/internal/java/service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (p *javaServiceClient) Evaluate(ctx context.Context, cap string, conditionI
}

symbols := p.GetAllSymbols(ctx, cond.Referenced.Pattern, cond.Referenced.Location)
p.log.Info("Symbols retrieved", "symbols", symbols)
p.log.V(5).Info("Symbols retrieved", "symbols", symbols)

incidents := []provider.IncidentContext{}
switch locationToCode[strings.ToLower(cond.Referenced.Location)] {
Expand Down

0 comments on commit 9369083

Please sign in to comment.