From 3cee15a9cbc9e257145b32d779d6cc65763aa640 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 23 May 2019 15:09:11 -0400 Subject: [PATCH] Move proxy shutdown to take place in a new thread. --- .../velocitypowered/proxy/VelocityServer.java | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 0c3e54735..0ef9991a1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -355,30 +355,36 @@ public class VelocityServer implements ProxyServer { if (!shutdownInProgress.compareAndSet(false, true)) { return; } - logger.info("Shutting down the proxy..."); - for (ConnectedPlayer player : ImmutableList.copyOf(connectionsByUuid.values())) { - player.disconnect(TextComponent.of("Proxy shutting down.")); - } + Runnable shutdownProcess = () -> { + logger.info("Shutting down the proxy..."); - this.cm.shutdown(); - - try { - if (!eventManager.shutdown() || !scheduler.shutdown()) { - logger.error("Your plugins took over 10 seconds to shut down."); + for (ConnectedPlayer player : ImmutableList.copyOf(connectionsByUuid.values())) { + player.disconnect(TextComponent.of("Proxy shutting down.")); } - } catch (InterruptedException e) { - // Not much we can do about this... - Thread.currentThread().interrupt(); - } - eventManager.fireShutdownEvent(); + this.cm.shutdown(); - shutdown = true; + try { + if (!eventManager.shutdown() || !scheduler.shutdown()) { + logger.error("Your plugins took over 10 seconds to shut down."); + } + } catch (InterruptedException e) { + // Not much we can do about this... + Thread.currentThread().interrupt(); + } - if (explicitExit) { - System.exit(0); - } + eventManager.fireShutdownEvent(); + + shutdown = true; + + if (explicitExit) { + System.exit(0); + } + }; + + Thread thread = new Thread(shutdownProcess); + thread.start(); } public NettyHttpClient getHttpClient() {