From 7beb8bee6a30ceeab388cd84e5fa765846b64103 Mon Sep 17 00:00:00 2001 From: baranowb Date: Thu, 8 Oct 2020 09:22:36 +0200 Subject: [PATCH] [UNDERTOW-1794] add configurable delay/retry on close --- .../accesslog/DefaultAccessLogReceiver.java | 47 +++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/io/undertow/server/handlers/accesslog/DefaultAccessLogReceiver.java b/core/src/main/java/io/undertow/server/handlers/accesslog/DefaultAccessLogReceiver.java index 7e1fbe8b62..eb88ec48a9 100644 --- a/core/src/main/java/io/undertow/server/handlers/accesslog/DefaultAccessLogReceiver.java +++ b/core/src/main/java/io/undertow/server/handlers/accesslog/DefaultAccessLogReceiver.java @@ -59,7 +59,7 @@ public class DefaultAccessLogReceiver implements AccessLogReceiver, Runnable, Cl //0 = not running //1 = queued //2 = running - //3 = closing + //3 = closing/closed @SuppressWarnings("unused") private volatile int state = 0; @@ -81,6 +81,8 @@ public class DefaultAccessLogReceiver implements AccessLogReceiver, Runnable, Cl private boolean initialRun = true; private final boolean rotate; private final LogFileHeaderGenerator fileHeaderGenerator; + private final int closeRetryCount; + private final int closeRetryDelay; public DefaultAccessLogReceiver(final Executor logWriteExecutor, final File outputDirectory, final String logBaseName) { this(logWriteExecutor, outputDirectory.toPath(), logBaseName, null); @@ -103,10 +105,10 @@ public DefaultAccessLogReceiver(final Executor logWriteExecutor, final Path outp } public DefaultAccessLogReceiver(final Executor logWriteExecutor, final Path outputDirectory, final String logBaseName, final String logNameSuffix, boolean rotate) { - this(logWriteExecutor, outputDirectory, logBaseName, logNameSuffix, rotate, null); + this(logWriteExecutor, outputDirectory, logBaseName, logNameSuffix, rotate, null, 60, 50); } - private DefaultAccessLogReceiver(final Executor logWriteExecutor, final Path outputDirectory, final String logBaseName, final String logNameSuffix, boolean rotate, LogFileHeaderGenerator fileHeader) { + private DefaultAccessLogReceiver(final Executor logWriteExecutor, final Path outputDirectory, final String logBaseName, final String logNameSuffix, boolean rotate, LogFileHeaderGenerator fileHeader, final int closeRetryCount, final int closeRetryDelay) { this.logWriteExecutor = logWriteExecutor; this.outputDirectory = outputDirectory; this.logBaseName = logBaseName; @@ -115,6 +117,8 @@ private DefaultAccessLogReceiver(final Executor logWriteExecutor, final Path out this.logNameSuffix = (logNameSuffix != null) ? logNameSuffix : DEFAULT_LOG_SUFFIX; this.pendingMessages = new ConcurrentLinkedDeque<>(); this.defaultLogFile = outputDirectory.resolve(logBaseName + this.logNameSuffix); + this.closeRetryCount = closeRetryCount; + this.closeRetryDelay = closeRetryDelay; calculateChangeOverPoint(); } @@ -352,10 +356,10 @@ public void close() throws IOException { return; } // either failed race to 1->3 or we were in 2. We have to wait here sometime. - // wait ~1s, if situation does not clear up, try dumping stuff - for(int i=0; i<20;i++) { + // wait ~3s(by default), if situation does not clear up, try dumping stuff + for(int i=0; i