From 8faa8a1bae0b24a2c41ab7c8f3e2e2cd517e4a92 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 --- .../bootstrap/logging/QuarkusDelayedHandler.java | 15 +++++++++++++++ 1 file changed, 15 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 6fe4b7ed49268d..3d42376bf25c08 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,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