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

Add protection against log queue overruns #15636

Merged
merged 1 commit into from
Mar 12, 2021
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
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,13 @@ 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