Skip to content
Permalink
Browse files
[FIXED JENKINS-22326] Do not reuse a SupportLogFormatter across handl…
…ers.

Its lock could be held while calling toString on something which might in turn log something against another handler.
  • Loading branch information
jglick committed Mar 24, 2014
1 parent 82ba5bc commit d7af2fa1ff7d8afc4b2d4b7ac247e3c02d4e7ee7
Showing with 11 additions and 5 deletions.
  1. +11 −5 src/main/java/com/cloudbees/jenkins/support/impl/JenkinsLogs.java
@@ -53,7 +53,6 @@
@Extension(ordinal = 100.0) // put this first as largest content and can let the slower ones complete
public class JenkinsLogs extends Component {

private final Formatter formatter = new SupportLogFormatter();
private final Map<String,LogRecorder> logRecorders = Jenkins.getInstance().getLog().logRecorders;
private final File customLogs = new File(new File(Jenkins.getInstance().getRootDir(), "logs"), "custom");

@@ -76,6 +75,7 @@ public void start(@NonNull SupportContext context) {

@Override
public void addContents(@NonNull Container result) {
final Formatter formatter = new SupportLogFormatter();
result.add(new PrintedContent("nodes/master/logs/jenkins.log") {
@Override
protected void printTo(PrintWriter out) throws IOException {
@@ -301,14 +301,20 @@ public static boolean isRequired() {
stream = new ReopenableRotatingFileOutputStream(new File(customLogs, name + ".log"), 9);
// TODO there is no way to avoid rotating when first opened; if .rewind is skipped, the file is just truncated
stream.rewind();
handler = new StreamHandler(stream, formatter);
handler = new StreamHandler(stream, new SupportLogFormatter());
handler.setLevel(Level.ALL);
count = 0;
}
synchronized void publish(LogRecord record) throws IOException {
if (count++ > 9999) { // make sure it does not get enormous during a single session
void publish(LogRecord record) throws IOException {
boolean rewind = false;
synchronized (this) {
if (count++ > 9999) { // make sure it does not get enormous during a single session
count = 0;
rewind = true;
}
}
if (rewind) {
stream.rewind();
count = 0;
}
handler.publish(record);
LogFlusher.scheduleFlush(handler);

0 comments on commit d7af2fa

Please sign in to comment.