Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-68122] Avoid deadlock involving RingBufferLogHandler.LogRecordRef class loading (III) #6449

Merged
merged 1 commit into from
Apr 9, 2022
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
12 changes: 12 additions & 0 deletions core/src/main/java/hudson/util/RingBufferLogHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@

package hudson.util;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.lang.ref.SoftReference;
import java.util.AbstractList;
import java.util.List;
import java.util.Objects;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
Expand All @@ -36,6 +38,9 @@
*
* @author Kohsuke Kawaguchi
*/
@SuppressFBWarnings(
value = "RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT",
justification = "to guard against potential future compiler optimizations")
public class RingBufferLogHandler extends Handler {

private static final int DEFAULT_RING_BUFFER_SIZE = Integer.getInteger(RingBufferLogHandler.class.getName() + ".defaultSize", 256);
Expand All @@ -46,6 +51,13 @@ private static final class LogRecordRef extends SoftReference<LogRecord> {
}
}

static {
// Preload the LogRecordRef class to avoid an ABBA deadlock between agent class loading and logging.
LogRecord r = new LogRecord(Level.INFO, "<preloading>");
// We call Objects.hash() to guard against potential future compiler optimizations.
Objects.hash(new LogRecordRef(r).get());
}

private int start = 0;
private final LogRecordRef[] records;
private int size;
Expand Down