Skip to content

Commit

Permalink
Add shutdown lock logger/workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Dec 9, 2024
1 parent ac1bc81 commit 28ac225
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/main/java/xyz/nucleoid/extras/NucleoidExtras.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import eu.pb4.playerdata.api.PlayerDataApi;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
Expand Down Expand Up @@ -61,10 +62,44 @@ public void onInitialize() {
PlayerDataApi.register(PlayerLobbyState.STORAGE);

ServerTickEvents.END_SERVER_TICK.register(NucleoidExtras::onServerTick);
ServerLifecycleEvents.SERVER_STOPPED.register(NucleoidExtras::onServerStopped);
ServerPlayConnectionEvents.JOIN.register(NucleoidExtras::onPlayerJoin);
NucleoidExtrasNetworking.register();
}

private static void onServerStopped(MinecraftServer server) {
if (!server.isDedicated()) {
return;
}

var thread = new Thread(() -> {
try {
Thread.sleep(20 * 1000);
} catch (InterruptedException e) {
// Ignored
}

LOGGER.warn("Server is still running, even through it should shutdown!");
for (var t : Thread.getAllStackTraces().keySet()) {
if (!t.isDaemon()) {
LOGGER.warn("- {}", t.getName());
}
}
try {
Thread.sleep(5 * 1000);
for (var t : Thread.getAllStackTraces().keySet()) {
t.interrupt();
}
Thread.sleep(5 * 1000);
} catch (InterruptedException e) {
// Ignored
}
System.exit(1);
}, "fallback shutdown");
thread.setDaemon(true);
thread.start();
}

private static void onPlayerJoin(ServerPlayNetworkHandler handler, PacketSender sender, MinecraftServer server) {
Calendar calendar = Calendar.getInstance();
if (calendar.get(Calendar.YEAR) == 2023 && calendar.get(Calendar.MONTH) == Calendar.DECEMBER) {
Expand Down

0 comments on commit 28ac225

Please sign in to comment.