Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak introduced with the fix of JENKINS-36372 #41

Merged
merged 6 commits into from
Aug 15, 2016

Conversation

jglick
Copy link
Member

@jglick jglick commented Aug 12, 2016

Had disabled a test due to still-undiagnosed failures on Jenkins 2, which concealed the fact that a recent bug fix (#29) regressed the leak on Jenkins 1:

{groovy.lang.GroovyClassLoader$InnerLoader@571df0f9=private static final org.jboss.marshalling.reflect.SerializableClassRegistry org.jboss.marshalling.reflect.SerializableClassRegistry.INSTANCE->
org.jboss.marshalling.reflect.SerializableClassRegistry@67289b2f-registry->
org.jboss.marshalling.reflect.UnlockedHashMap@46269dbf-table->
org.jboss.marshalling.reflect.UnlockedHashMap$Table@4a13d1ef-array->
[Ljava.lang.Object;@2b2b3f3-[121]->
[Lorg.jboss.marshalling.reflect.UnlockedHashMap$Item;@182e8565-[0]->
org.jboss.marshalling.reflect.UnlockedHashMap$Item@13d66b69-key->
groovy.lang.GroovyClassLoader$InnerLoader@571df0f9}

@reviewbybees

…cting a memory leak regression introduced with the fix of JENKINS-36372 in 2.9.
@@ -63,6 +63,7 @@
</pluginRepositories>
<properties>
<jenkins.version>1.642.3</jenkins.version>
<jenkins-test-harness.version>2.15-SNAPSHOT</jenkins-test-harness.version>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downstream of jenkinsci/jenkins-test-harness#32. Actually passes without this dependency, but takes three times as long to collect the reference, due to lack of exponential escalation in the original version.

@ghost
Copy link

ghost commented Aug 12, 2016

This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation.

@Test public void loaderReleased() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
Assume.assumeThat("TODO fails in Jenkins 2 for reasons TBD (no root references detected)", Jenkins.VERSION, Matchers.startsWith("1."));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional calls to fromRoots in the upstream PR were an attempt to diagnose this, so far without success.

@jglick
Copy link
Member Author

jglick commented Aug 12, 2016

Seem to be test failures, trying to figure out what they mean.

@@ -391,6 +393,10 @@ private void run() throws IOException {
if (doneSomeWork) {
saveProgram();
}
if (ending) {
execution.cleanUpHeap();
scripts.clear();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing scripts (introduced in #29) was also necessary, or even with the fix to the timing of SerializableClassRegistry.release, the test would still fail on Jenkins 1. The failure showed no root references, so I had to guess at the cause.

@jglick
Copy link
Member Author

jglick commented Aug 12, 2016

FindBugs failure, will deal with it.

In the meantime I found the cause of the Jenkins 2 failure at last:

groovy.lang.GroovyClassLoader$InnerLoader [Stack Local]
<loader> of WorkflowScript
klazz of org.codehaus.groovy.reflection.ClassInfo
value of org.codehaus.groovy.reflection.GroovyClassValuePreJava7$EntryWithValue
[0] of java.lang.Object[3]
[12] of java.lang.Object[32]
table of org.codehaus.groovy.reflection.GroovyClassValuePreJava7$GroovyClassValuePreJava7Segment
[14] of org.codehaus.groovy.util.AbstractConcurrentMapBase$Segment[16]
segments of org.codehaus.groovy.reflection.GroovyClassValuePreJava7$GroovyClassValuePreJava7Map
map of org.codehaus.groovy.reflection.GroovyClassValuePreJava7
globalClassValue of org.codehaus.groovy.reflection.ClassInfo
[6128] of java.lang.Object[20480]
elementData of java.util.Vector size = 13,066
classes of sun.misc.Launcher$AppClassLoader [Stack Local]
contextClassLoader of java.util.TimerThread [Thread, Stack Local]  "Timer-2" daemon tid=78 [TIMED_WAITING]

Unless you are running on IBM J9 VM, Groovy 2 switches to a broken GroovyClassValuePreJava7 which leaks ClassLoaders. (They claim to be affected by JDK-8136353 but I think the mistake is in Groovy, not Java.) The switch is controlled by a system property, but you would have to set it before Jenkins starts, so Pipeline cannot do so. So I am looking for a way to either clear all values from ClassInfo.globalClassValue (unfortunately Groovy’s nonstandard map implementations lack a clear method), or reset the whole collection to a version that works better (which is scary since it will affect every use of Groovy in Jenkins, pending JENKINS-29068), or somehow look up individual Class entries and clear them.

@jglick
Copy link
Member Author

jglick commented Aug 12, 2016

With a patched INSANE, I can now diagnose the problem properly in the test:

{groovy.lang.GroovyClassLoader$InnerLoader@368430db=private static final org.codehaus.groovy.reflection.GroovyClassValue org.codehaus.groovy.reflection.ClassInfo.globalClassValue->
org.codehaus.groovy.reflection.GroovyClassValuePreJava7@1a70d5df-map->
org.codehaus.groovy.reflection.GroovyClassValuePreJava7$GroovyClassValuePreJava7Map@54d79178-segments->
[Lorg.codehaus.groovy.util.AbstractConcurrentMapBase$Segment;@4a3f3c19-[12]->
org.codehaus.groovy.reflection.GroovyClassValuePreJava7$GroovyClassValuePreJava7Segment@3aa898c1-table->
[Ljava.lang.Object;@4bb9c2ea-[11]->
org.codehaus.groovy.reflection.GroovyClassValuePreJava7$EntryWithValue@274aa2f8-value->
org.codehaus.groovy.reflection.ClassInfo@3eacd88f-klazz->
java.lang.Class@4f65c3ca-<changed>->
groovy.lang.GroovyClassLoader$InnerLoader@368430db}

@jglick
Copy link
Member Author

jglick commented Aug 12, 2016

Fixed that problem what I can tell, but now the test fails again on Jenkins 2 with no apparent GC root path. Heap analysis tools just tell me that the InnerLoader is being held as a “JNI global”, which does not say much. So I guess I leave it as is and hope this leak does not manifest itself in production.


// clean up heap
void cleanUpHeap() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SerializableClassRegistry.release was getting called on the right loader, but too soon—before the final call to saveProgram, which would up adding the loader back to the registry. Not sure when this regressed—presumably at some point after the test was disabled.

@abayer
Copy link
Member

abayer commented Aug 12, 2016

🐝

@jglick jglick merged commit 2f1580d into jenkinsci:master Aug 15, 2016
@jglick jglick deleted the CpsFlowExecutionTest.loaderReleased branch August 15, 2016 13:14
svanoort pushed a commit that referenced this pull request Sep 28, 2017
dwnusbaum pushed a commit to dwnusbaum/workflow-cps-plugin that referenced this pull request Jun 1, 2020
Added support for super.foo(...) calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants