Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,19 @@ private Env createInitialEnv() {

private CpsScript parseScript() throws IOException {
// classloader hierarchy. See doc/classloader.md
trusted = new CpsGroovyShellFactory(this).forTrusted().build();
shell = new CpsGroovyShellFactory(this).withParent(trusted).build();
CpsScript s;
try {
trusted = new CpsGroovyShellFactory(this).forTrusted().build();
shell = new CpsGroovyShellFactory(this).withParent(trusted).build();

CpsScript s = (CpsScript) shell.reparse("WorkflowScript",script);
s = (CpsScript) shell.reparse("WorkflowScript",script);

for (Entry<String, String> e : loadedScripts.entrySet()) {
shell.reparse(e.getKey(), e.getValue());
for (Entry<String, String> e : loadedScripts.entrySet()) {
shell.reparse(e.getKey(), e.getValue());
}
} catch (RuntimeException | Error x) {
closeShells();
throw x;
}

s.execution = this;
Expand Down Expand Up @@ -1304,20 +1310,26 @@ synchronized void onProgramEnd(Outcome outcome) {
this.persistedClean = Boolean.TRUE;
}

void cleanUpHeap() {
LOGGER.log(Level.FINE, "cleanUpHeap on {0}", owner);
private void closeShells() {
try {
if (shell != null) {
LOGGER.fine(() -> "closing main class loader from " + owner);
shell.getClassLoader().close();
shell = null;
}
if (trusted != null) {
LOGGER.fine(() -> "closing trusted class loader from " + owner);
trusted.getClassLoader().close();
trusted = null;
}
} catch (IOException x) {
LOGGER.log(Level.WARNING, "failed to close class loaders from " + owner, x);
}
}

void cleanUpHeap() {
LOGGER.log(Level.FINE, "cleanUpHeap on {0}", owner);
closeShells();
if (scriptClass != null) {
try {
cleanUpLoader(scriptClass.getClassLoader(), new HashSet<>(), new HashSet<>());
Expand Down