Force exiting server on shutdown (#415)
This commit is contained in:
parent
aba187d46e
commit
04859a24c4
|
@ -0,0 +1,18 @@
|
||||||
|
package io.izzel.arclight.common.mixin.bukkit;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
|
import org.bukkit.craftbukkit.v.scheduler.CraftScheduler;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
|
||||||
|
@Mixin(value = CraftScheduler.class, remap = false)
|
||||||
|
public class CraftSchedulerMixin {
|
||||||
|
|
||||||
|
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/google/common/util/concurrent/ThreadFactoryBuilder;build()Ljava/util/concurrent/ThreadFactory;"))
|
||||||
|
private ThreadFactory arclight$setDaemon(ThreadFactoryBuilder instance) {
|
||||||
|
return instance.setDaemon(true).build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package io.izzel.arclight.common.mixin.core.server.dedicated;
|
package io.izzel.arclight.common.mixin.core.server.dedicated;
|
||||||
|
|
||||||
import io.izzel.arclight.common.mixin.core.server.MinecraftServerMixin;
|
import io.izzel.arclight.common.mixin.core.server.MinecraftServerMixin;
|
||||||
|
import io.izzel.arclight.common.mod.ArclightMod;
|
||||||
import io.izzel.arclight.common.mod.server.BukkitRegistry;
|
import io.izzel.arclight.common.mod.server.BukkitRegistry;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
|
@ -25,6 +26,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mixin(DedicatedServer.class)
|
@Mixin(DedicatedServer.class)
|
||||||
public abstract class DedicatedServerMixin extends MinecraftServerMixin {
|
public abstract class DedicatedServerMixin extends MinecraftServerMixin {
|
||||||
|
@ -88,7 +91,28 @@ public abstract class DedicatedServerMixin extends MinecraftServerMixin {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
new Thread(() -> System.exit(0), "Exit Thread").start();
|
Thread exitThread = new Thread(this::arclight$exit, "Exit Thread");
|
||||||
|
exitThread.setDaemon(true);
|
||||||
|
exitThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void arclight$exit() {
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000L);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
List<String> threads = new ArrayList<>();
|
||||||
|
for (Thread thread : Thread.getAllStackTraces().keySet()) {
|
||||||
|
if (!thread.isDaemon() && !thread.getName().equals("DestroyJavaVM")) {
|
||||||
|
threads.add(thread.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!threads.isEmpty()) {
|
||||||
|
ArclightMod.LOGGER.debug("Threads {} not shutting down", String.join(", ", threads));
|
||||||
|
ArclightMod.LOGGER.warn("{} threads not shutting down correctly, force exiting", threads.size());
|
||||||
|
}
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
"CraftMetaItemMixin",
|
"CraftMetaItemMixin",
|
||||||
"CraftPlayerMixin",
|
"CraftPlayerMixin",
|
||||||
"CraftRegionAccessorMixin",
|
"CraftRegionAccessorMixin",
|
||||||
|
"CraftSchedulerMixin",
|
||||||
"CraftServerMixin",
|
"CraftServerMixin",
|
||||||
"CraftVillagerMixin",
|
"CraftVillagerMixin",
|
||||||
"CraftWorldMixin",
|
"CraftWorldMixin",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user