Skip to content

Commit

Permalink
[FIXED JENKINS-26030] Close logger streams after the owning node fini…
Browse files Browse the repository at this point in the history
…shes, so we do not leak file handles.

Originally-Committed-As: 7608ed3dc3c77fbfd946697869d4e669c1fc334b
  • Loading branch information
jglick committed Dec 11, 2014
1 parent 663339f commit d054b77
Showing 1 changed file with 14 additions and 0 deletions.
Expand Up @@ -36,11 +36,14 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import jenkins.model.CoreEnvironmentContributor;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.flow.GraphListener;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.support.actions.EnvironmentAction;
Expand Down Expand Up @@ -83,6 +86,17 @@ public abstract class DefaultStepContext extends StepContext {
}

listener = new StreamTaskListener(new FileOutputStream(la.getLogFile(), true));
getExecution().addListener(new GraphListener() {
@Override public void onNewHead(FlowNode node) {
try {
if (!getNode().isRunning()) {
listener.getLogger().close();
}
} catch (IOException x) {
Logger.getLogger(DefaultStepContext.class.getName()).log(Level.FINE, null, x);
}
}
});
}
return key.cast(listener);
} else if (Node.class.isAssignableFrom(key)) {
Expand Down

0 comments on commit d054b77

Please sign in to comment.