From 40ad52987f9715ae38cd7b9db20e73d6dd2beba0 Mon Sep 17 00:00:00 2001 From: zzz Date: Sat, 29 Aug 2026 12:17:50 -0400 Subject: [PATCH] Router: Ensure log gzipper finishes after shutdown signal --- core/java/src/net/i2p/util/FileLogWriter.java | 8 ++++++-- router/java/src/net/i2p/router/Router.java | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/java/src/net/i2p/util/FileLogWriter.java b/core/java/src/net/i2p/util/FileLogWriter.java index c9b0d7021..d8729f93d 100644 --- a/core/java/src/net/i2p/util/FileLogWriter.java +++ b/core/java/src/net/i2p/util/FileLogWriter.java @@ -118,13 +118,17 @@ class FileLogWriter extends LogWriter { } catch (IOException ioe) {} } if (_manager.shouldGzip() && currentFile != null && currentFile.length() >= _manager.getMinGzipSize()) { + // we always start a non-daemon thread for this, + // because the thread we are in now is a daemon thread. Thread gzipper = new Gzipper(currentFile); if (threadGzipper) { + // rotate gzipper.setPriority(Thread.MIN_PRIORITY); - gzipper.start(); // rotate } else { - gzipper.run(); // shutdown + // shutdown + gzipper.setPriority(Thread.MAX_PRIORITY - 1); } + gzipper.start(); } } diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java index c06ce38af..4b8a65a77 100644 --- a/router/java/src/net/i2p/router/Router.java +++ b/router/java/src/net/i2p/router/Router.java @@ -1713,7 +1713,12 @@ public class Router implements RouterClock.ClockShiftListener { changeState(State.FINAL_SHUTDOWN_3); clearCaches(); _log.log(Log.CRIT, "Shutdown(" + exitCode + ") complete" /* , new Exception("Shutdown") */ ); + boolean waitForGzip = _context.logManager().shouldGzip(); try { _context.logManager().shutdown(); } catch (Throwable t) { } + if (waitForGzip && !_killVMOnEnd) { + // ShutdownHook calls setKillVMOnEnd(false) + try { Thread.sleep(2000); } catch (InterruptedException ie) {} + } if (ALLOW_DYNAMIC_KEYS) { if (_context.getBooleanProperty(PROP_DYNAMIC_KEYS)) killKeys();