Skip to content

fix: Fix resource leak by wrapping GroovyClassLoader in try-with-resources#1497

Open
ArpanC6 wants to merge 2 commits intojenkinsci:mainfrom
ArpanC6:fix/resource-leak-clean
Open

fix: Fix resource leak by wrapping GroovyClassLoader in try-with-resources#1497
ArpanC6 wants to merge 2 commits intojenkinsci:mainfrom
ArpanC6:fix/resource-leak-clean

Conversation

@ArpanC6
Copy link
Copy Markdown

@ArpanC6 ArpanC6 commented Mar 15, 2026

Summary

Fixes a resource leak in GroovyClassLoader by wrapping it in try-with-resources.

Changes

  • Wrapped GroovyClassLoader instantiation in try-with-resources block
  • Ensures GroovyClassLoader is properly closed after use

Testing

  • mvn compile passes

@ArpanC6 ArpanC6 requested a review from a team as a code owner March 15, 2026 05:29
@ArpanC6
Copy link
Copy Markdown
Author

ArpanC6 commented Mar 15, 2026

"The linux-25 test failures appear to be pre-existing and unrelated to this change. The windows-21 build passes successfully with the same code. This PR only wraps GroovyClassLoader in try-with-resources and does not modify any script execution logic."

@ArpanC6
Copy link
Copy Markdown
Author

ArpanC6 commented Mar 17, 2026

The test failures appear to be pre-existing and unrelated to this change.
The linux-25/Build junit error exists in the upstream codebase.
This PR only wraps GroovyClassLoader in try-with-resources and does not
modify any test or script execution logic.

@ArpanC6
Copy link
Copy Markdown
Author

ArpanC6 commented Mar 17, 2026

The CodeQL security scan failure is unrelated to this PR. The build fails in MailAccount.java at line 170 due to a pre-existing API incompatibility — org.acegisecurity.Authentication cannot be converted to org.springframework.security.core.Authentication. This file was not modified in this PR. The same compilation error would occur on any PR that triggers the CodeQL autobuild.

gloader.addURL(entry.getURL());
}
gloader.addURL(entry.getURL());
loader = gloader;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Won't this still keep it alive since it is being reassigned to loader?

@ArpanC6
Copy link
Copy Markdown
Author

ArpanC6 commented Mar 23, 2026

Hi @slide I've addressed your feedback

  1. Fixed the resource leak by returning within the try with-resources block instead of reassigning to loader
  2. Removed .vscode/settings.json
  3. Removed the unrelated ACL.SYSTEM2 change from this PR

Please let me know if any further changes are needed. Thank you..

@ArpanC6 ArpanC6 force-pushed the fix/resource-leak-clean branch from 14d7a15 to 1820f05 Compare March 23, 2026 18:55
@ArpanC6
Copy link
Copy Markdown
Author

ArpanC6 commented Mar 23, 2026

Hi @slide I've squashed the commits and the PR now contains only the single file change to ExtendedEmailPublisher.java. Please let me know if any further changes are needed. Thank you...

@ArpanC6 ArpanC6 force-pushed the fix/resource-leak-clean branch from 41b0cba to 8b54785 Compare March 23, 2026 20:21
@ArpanC6
Copy link
Copy Markdown
Author

ArpanC6 commented Mar 23, 2026

Hi @slide I've fixed the resource leak by closing the GroovyClassLoader in a finally block within executeScript() after script execution completes rather than in expandClasspath(). This ensures the classloader stays alive during script execution but is properly closed afterward. All 365 tests are now passing. Please let me know if any further changes are needed. Thank you..

@ArpanC6
Copy link
Copy Markdown
Author

ArpanC6 commented Mar 27, 2026

Hi @slide just following up on this PR. Please let me know if any further changes are needed. Happy to update. Thank you..

@ArpanC6
Copy link
Copy Markdown
Author

ArpanC6 commented Apr 4, 2026

@slide just wanted to check in on this PR. I have addressed all the
previous feedback fixed the resource leak by closing the GroovyClassLoader
in a finally block removed the unrelated changes and all CI checks are
passing. Please let me know if any further changes are needed. Happy to update.

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.

3 participants