Skip to content

Commit

Permalink
Add protection against log queue overruns
Browse files Browse the repository at this point in the history
Fixes #15220
  • Loading branch information
dmlloyd committed Mar 11, 2021
1 parent 258d74e commit 14d5c07
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.logging.ErrorManager;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Logger;
Expand All @@ -36,10 +37,19 @@ public class QuarkusDelayedHandler extends ExtHandler {

private final Deque<ExtLogRecord> logRecords = new ArrayDeque<>();

private final int queueLimit;
private volatile boolean buildTimeLoggingActivated = false;
private volatile boolean activated = false;
private volatile boolean callerCalculationRequired = false;

public QuarkusDelayedHandler() {
this(4000);
}

public QuarkusDelayedHandler(final int queueLimit) {
this.queueLimit = queueLimit;
}

@Override
protected void doPublish(final ExtLogRecord record) {
// If activated just delegate
Expand All @@ -53,6 +63,11 @@ protected void doPublish(final ExtLogRecord record) {
publishToNestedHandlers(record);
super.doPublish(record);
} else {
// Determine whether the queue was overrun
if (logRecords.size() >= queueLimit) {
reportError("The delayed handler's queue was overrun and log record(s) were lost. Did you forget to configure logging?", null, ErrorManager.WRITE_FAILURE);
return;
}
// Determine if we need to calculate the caller information before we queue the record
if (isCallerCalculationRequired()) {
// prepare record to move to another thread
Expand Down

0 comments on commit 14d5c07

Please sign in to comment.