From df7eb4ade0ec5b7ae75c3859a7d7436b482f5794 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 23 May 2019 14:50:58 -0400 Subject: [PATCH] Ensure the proxy doesn't shut down too early if stdin is EOF. --- proxy/src/main/java/com/velocitypowered/proxy/Velocity.java | 5 +++++ .../main/java/com/velocitypowered/proxy/VelocityServer.java | 4 ++++ .../com/velocitypowered/proxy/network/ConnectionManager.java | 4 ++++ 3 files changed, 13 insertions(+) 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; }