From 1748cd3135c64aa737d08bf55b2194f1d88e4976 Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Wed, 10 Mar 2021 10:55:12 -0600 Subject: [PATCH] Add protection against log queue overruns Fixes #15220 --- .../logging/QuarkusDelayedHandler.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/logging/QuarkusDelayedHandler.java b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/logging/QuarkusDelayedHandler.java index 6fe4b7ed49268..ae28d6fc633f5 100644 --- a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/logging/QuarkusDelayedHandler.java +++ b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/logging/QuarkusDelayedHandler.java @@ -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; @@ -36,10 +37,19 @@ public class QuarkusDelayedHandler extends ExtHandler { private final Deque 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 @@ -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