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

URLClassLoader leak in PluginLoader #2024

Closed
gtoison opened this issue Apr 21, 2022 · 1 comment
Closed

URLClassLoader leak in PluginLoader #2024

gtoison opened this issue Apr 21, 2022 · 1 comment

Comments

@gtoison
Copy link
Contributor

gtoison commented Apr 21, 2022

PluginLoader creates some URLClassLoader and never closes them. When the URLClassLoader points to a .jar file, the JVM process keeps a reference to that file (a RandomAccessFile instance) preventing from deleting/renaming that .jar file.
This is an issue when the JVM process is long lived, for instance when it's running inside the Gradle daemon (see spotbugs/sonar-findbugs#128)

The RandomAccessFile is created as soon as the classloader opens the .jar file, which for me was when looking for the non-existing resource messages_en_GB.xml. The URL does not exist because the .jar does not contain it so calling JarURLConnection.setUseCaches() wouldn't help here.

To sum up, this code reproduces the issue: omitting the close() on the last line creates a lock on the plugin jar file until the JVM process is stopped.

URLClassLoader classLoader = new URLClassLoader(new URL[] {workingPluginFile.toURI().toURL()});
classLoader.findResource("messages_en_GB.xml");
classLoader.close();
@gtoison
Copy link
Contributor Author

gtoison commented Jun 1, 2022

This can be closed now that #2025 is merged

@gtoison gtoison closed this as completed Jun 1, 2022
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

No branches or pull requests

1 participant