Skip to content

Commit

Permalink
Fixed unloading modules not actually freeing the handles to the files…
Browse files Browse the repository at this point in the history
…, making it impossible to delete the jar until the entire server stops
  • Loading branch information
OmerBenGera committed Dec 24, 2022
1 parent c2f7edd commit efa054d
Showing 1 changed file with 13 additions and 0 deletions.
Expand Up @@ -18,6 +18,7 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Stream;
Expand Down Expand Up @@ -94,6 +95,18 @@ public void unregisterModule(PluginModule pluginModule) {
}

this.modulesContainer.unregisterModule(pluginModule);

// We now want to unload the ClassLoader and free the held handles for the file.
ClassLoader classLoader = pluginModule.getClassLoader();
if (classLoader instanceof URLClassLoader) {
try {
((URLClassLoader) classLoader).close();
// This is an attempt to force Windows to free the handles of the file.
System.gc();
} catch (IOException ignored) {
}
}

}

@Override
Expand Down

0 comments on commit efa054d

Please sign in to comment.