diff options
| author | Sho Sakuma <me@m1sk9.dev> | 2026-08-05 00:42:19 +0900 |
|---|---|---|
| committer | Sho Sakuma <me@m1sk9.dev> | 2026-08-05 00:42:25 +0900 |
| commit | c037fef7d7821cb0968b183e6108a416dba5cf83 (patch) | |
| tree | a4adedec06f9d6ee883dd62c625315a89eeadab8 | |
| parent | 8870ca5de9dd091830a6c3b80a5fcc4f8f035360 (diff) | |
| download | LunaticChat-c037fef7d7821cb0968b183e6108a416dba5cf83.tar.gz LunaticChat-c037fef7d7821cb0968b183e6108a416dba5cf83.tar.bz2 LunaticChat-c037fef7d7821cb0968b183e6108a416dba5cf83.zip | |
fix: let shutdown finish when a save fails
The steps ran as one statement each, so the first exception escaped
onDisable and took the rest with it - leaving the channel message logger
unflushed and the Velocity connection to be torn down by the server rather
than by us. Each step is independent, so a failure is now reported and the
remaining ones still run.
Co-Authored-By: Claude <noreply@anthropic.com>
| -rw-r--r-- | platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/ServiceInitializer.kt | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/ServiceInitializer.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/ServiceInitializer.kt index 1029c40..5ec2e0a 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/ServiceInitializer.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/ServiceInitializer.kt @@ -25,6 +25,7 @@ import org.bukkit.event.player.PlayerJoinEvent import org.bukkit.plugin.java.JavaPlugin import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicBoolean +import java.util.logging.Level import java.util.logging.Logger import kotlin.time.Duration.Companion.milliseconds @@ -452,10 +453,24 @@ class ServiceInitializer( * Performs shutdown tasks, including saving all caches to disk. */ fun shutdown(services: ServiceContainer) { - services.playerSettingsManager.saveToDisk() - services.conversionCache?.saveToDisk() - services.channelManager?.saveToDisk() - services.channelMessageLogger?.shutdown() - services.velocityConnectionManager?.shutdown() + shutdownStep("save player settings") { services.playerSettingsManager.saveToDisk() } + shutdownStep("save the conversion cache") { services.conversionCache?.saveToDisk() } + shutdownStep("save channel data") { services.channelManager?.saveToDisk() } + shutdownStep("shut down the channel message logger") { services.channelMessageLogger?.shutdown() } + shutdownStep("shut down the Velocity connection") { services.velocityConnectionManager?.shutdown() } + } + + // The steps are independent, so one that throws must not skip the ones after it - which is what + // an exception escaping onDisable would do, leaving the log flusher and the Velocity connection + // to be torn down by the server instead. + private fun shutdownStep( + what: String, + step: () -> Unit, + ) { + try { + step() + } catch (e: Exception) { + logger.log(Level.SEVERE, "Failed to $what during shutdown", e) + } } } |
