Skip to content

Conversation

@dwnusbaum
Copy link
Member

@dwnusbaum dwnusbaum commented Sep 19, 2025

See jenkinsci/workflow-cps-plugin#1086.

Testing done

See new automated test.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

@jglick jglick added the tests label Sep 20, 2025
// is first initialized by a Pipeline that uses @Grab, the grabbed classes will be available when
// BulkFlowNodeStorage.XSTREAM2 is instantiated, causing them to be strongly retained.
// Specifically com.thoughtworks.xstream.converters.extended.DurationConverter and org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl cause problems.
// TODO: Should we add an @Initializer to BulkFlowNodeStorage.XSTREAM to avoid this?
Copy link
Member Author

Choose a reason for hiding this comment

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

I can do this to have the field loaded at a consistent time during startup, but as-is, at worst this will only leak resources from a single build.

Copy link
Member Author

Choose a reason for hiding this comment

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

clearInvocationCaches.setAccessible(true);
clearInvocationCaches.invoke(metaClass);

// TODO: GrapeIvy's $callSiteArray softly references the class that most recently used @Grab. I have not
Copy link
Member Author

Choose a reason for hiding this comment

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

In other words, if you change line 115 to for (int i = 0; i < 10; i++) r.buildAndAssertSuccess(p);, only the final build will be softly referenced by GrapeIvy's CallSiteArray and the others will be cleaned up promptly. So as far as real-world usage, at worst I think this would be a single-build leak.

}
}

@Test public void loaderReleasedWithGrab() throws Exception {
Copy link
Member Author

@dwnusbaum dwnusbaum Sep 24, 2025

Choose a reason for hiding this comment

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

Without jenkinsci/workflow-cps-plugin#1086, this test either passes very slowly, or fails, depending on whether or not the SoftReference is cleared prior to an OutOfMemoryError. With jenkinsci/jenkins-test-harness#1029 the failure becomes consistent.

With jenkinsci/workflow-cps-plugin#1086, the test passes quickly.

@dwnusbaum dwnusbaum marked this pull request as ready for review September 25, 2025 17:04
@dwnusbaum dwnusbaum requested a review from a team as a code owner September 25, 2025 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants