Skip to content

Commit

Permalink
[FIXED JENKINS-22326] Do not reuse a SupportLogFormatter across handl…
Browse files Browse the repository at this point in the history
…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 d7af2fa
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main/java/com/cloudbees/jenkins/support/impl/JenkinsLogs.java
Expand Up @@ -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");

Expand All @@ -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 {
Expand Down Expand Up @@ -301,14 +301,20 @@ private final class LogFile {
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);
Expand Down

0 comments on commit d7af2fa

Please sign in to comment.