Skip to content

Commit

Permalink
fix(leak): fix metaspace leak form preconfigured jobs (#3760)
Browse files Browse the repository at this point in the history
* fix(leak): fix metaspace leak form preconfigured jobs

Every execution of preconfigured job would run groovy.eval which in turn generates a script whose Klass stuffs is never released from metaspace
(similar issues: elastic/elasticsearch#18572 and https://hoangx281283.wordpress.com/2014/07/24/unload-groovy-classes/)

Unclear why there is a need to run `eval` here anyway, so removing it all-together

* fix(preconfigured): support traversing object graph for mappings

Co-authored-by: Cameron Fieber <cfieber@netflix.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 22, 2020
1 parent 2405630 commit 77ee2f8
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,32 @@ class PreconfiguredJobStage extends RunJobStage {
}
preconfiguredJob.parameters.each { defaults ->
if (defaults.defaultValue != null) {
Eval.xy(context, defaults.defaultValue, "x.${defaults.mapping} = y.toString()")
setNestedValue(context, defaults.mapping, defaults.defaultValue)
}
}
if (context.parameters) {
context.parameters.each { k, v ->
def parameterDefinition = preconfiguredJob.parameters.find { it.name == k }
if (parameterDefinition) {
Eval.xy(context, v, "x.${parameterDefinition.mapping} = y.toString()")
setNestedValue(context, parameterDefinition.mapping, v.toString())
}
}
}
context.preconfiguredJobParameters = preconfiguredJob.parameters
return context
}

private static void setNestedValue(Object root, String mapping, Object value) {
String[] props = mapping.split(/\./)
Object current = root
for (int i = 0; i < props.length - 1; i++) {
Object next = current[props[i]]
if (next == null) {
throw new IllegalArgumentException("no property ${props[i]} on $current")
}
current = next
}
current[props.last()] = value
}

}

0 comments on commit 77ee2f8

Please sign in to comment.