diff --git a/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java b/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java index c0a861f92..d00274735 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java @@ -45,5 +45,10 @@ public class Velocity { double bootTime = (System.currentTimeMillis() - startTime) / 1000d; logger.info("Done ({}s)!", new DecimalFormat("#.##").format(bootTime)); server.getConsoleCommandSource().start(); + + // If we don't have a console available (because SimpleTerminalConsole returned), then we still + // need to wait, otherwise the JVM will reap us as no non-daemon threads will be active once the + // main thread exits. + server.awaitProxyShutdown(); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 865b13036..0c3e54735 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -138,6 +138,10 @@ public class VelocityServer implements ProxyServer { return commandManager; } + void awaitProxyShutdown() { + cm.getBossGroup().terminationFuture().syncUninterruptibly(); + } + @EnsuresNonNull({"serverKeyPair", "servers", "pluginManager", "eventManager", "scheduler", "console", "cm", "configuration"}) void start() { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java index f5ef6ea81..e74e3e893 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java @@ -160,6 +160,10 @@ public final class ConnectionManager { } } + public EventLoopGroup getBossGroup() { + return bossGroup; + } + public ServerChannelInitializerHolder getServerChannelInitializer() { return this.serverChannelInitializer; }