From a88d27af763c1a08a44e40625e36543d9c24289c Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 7 Aug 2018 10:37:38 -0400 Subject: [PATCH] Ignore repeated shutdown requests. --- .../java/com/velocitypowered/proxy/VelocityServer.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 43c0365ec..633db78f2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -35,6 +35,7 @@ import java.nio.file.Paths; import java.security.KeyPair; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; public class VelocityServer implements ProxyServer { private static final Logger logger = LogManager.getLogger(VelocityServer.class); @@ -49,7 +50,7 @@ public class VelocityServer implements ProxyServer { private KeyPair serverKeyPair; private final ServerMap servers = new ServerMap(); private final CommandManager commandManager = new CommandManager(); - private boolean shutdown = false; + private final AtomicBoolean shutdown = new AtomicBoolean(false); private final Map connectionsByUuid = new ConcurrentHashMap<>(); private final Map connectionsByName = new ConcurrentHashMap<>(); @@ -136,15 +137,12 @@ public class VelocityServer implements ProxyServer { } public boolean isShutdown() { - return shutdown; + return shutdown.get(); } public void shutdown() { - Preconditions.checkState(!shutdown, "Server already shut down"); - shutdown = true; - + if (!shutdown.compareAndSet(false, true)) return; logger.info("Shutting down the proxy..."); - this.cm.shutdown(); }