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

Patch JGit FS class to prevent classloader memory leak #2544

Merged
merged 1 commit into from
Dec 17, 2022
Merged

Patch JGit FS class to prevent classloader memory leak #2544

merged 1 commit into from
Dec 17, 2022

Conversation

shanman190
Copy link
Contributor

When using the rewrite-gradle-plugin, JGit's FS class adds a Runtime shutdown hook that inadvertently creates a shadow reference to the RewriteClassLoader of the plugin's classpath isolation feature. This expands to effectively mean that each time the rewrite configuration is modified and a new RewriteClassLoader is created, the previous one is leaked on the heap without ever being able to be reclaimed by the garbage collector. The included patch here removes just the shutdown hook, so that we can stop leaking the classloader

When using the rewrite-gradle-plugin, JGit's FS class adds a Runtime shutdown hook that inadvertently creates a shadow reference to the RewriteClassLoader of the plugin's classpath isolation feature. This expands to effectively mean that each time the rewrite configuration is modified and a new RewriteClassLoader is created, the previous one is leaked on the heap without ever being able to be reclaimed by the garbage collector. The included patch here removes just the shutdown hook, so that we can stop leaking the classloader
@shanman190
Copy link
Contributor Author

This fixes openrewrite/rewrite-gradle-plugin gh-132.

@sambsnyd sambsnyd merged commit 2120ad1 into openrewrite:main Dec 17, 2022
sambsnyd added a commit that referenced this pull request Dec 17, 2022
sambsnyd pushed a commit that referenced this pull request Dec 17, 2022
* Revert "Revert "Patch JGit FS class to prevent classloader memory leak (#2544)""

This reverts commit dff2985.

* Use shadowJar for test classpath
@knutwannheden
Copy link
Contributor

@shanman190 Was a corresponding issue reported upstream? It would be nice if this patch could be removed at some point.

@shanman190
Copy link
Contributor Author

@knutwannheden, I hadn't yet as this was something that @sambsnyd and I found when running with the Gradle daemon.

Based on the upstream implementation, I suspect that JGit was really never intended to be run within an isolated classloader like we're doing for rewrite (there are a lot of runtime shutdown hooks beyond this one). I can see if I can't figure out how to file an issue on eclipse's bugzilla to see what insight we can get from them.

@knutwannheden
Copy link
Contributor

Sounds good. I happen to know one of the JGit committers. If you like I could ask him about his opinion on this use case.

@shanman190
Copy link
Contributor Author

@knutwannheden, yeah, if you've got an in that would be great to see what we can glean. Thanks!

@shanman190
Copy link
Contributor Author

@knutwannheden, did you ever hear back from that JGit committer?

@knutwannheden
Copy link
Contributor

@shanman190 He mentioned that he was rather busy at the moment and wouldn't have time to look into it. But I filed a ticket and we could look into submitting a change (they use Gerrit and not GitHub).

@sambsnyd sambsnyd added this to the 7.35.0 milestone Jan 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants