From 5773fe240be35890c967d4b33a7e80a763869123 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 28 Aug 2018 21:24:49 -0400 Subject: [PATCH 1/3] Use a HashSet here as it is more appropriate for the situation. --- .../velocitypowered/proxy/scheduler/VelocityScheduler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java b/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java index e3e7b342a..3e87ab911 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java @@ -12,7 +12,7 @@ import com.velocitypowered.api.scheduler.TaskStatus; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.ArrayList; +import java.util.HashSet; import java.util.IdentityHashMap; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReference; @@ -21,8 +21,8 @@ public class VelocityScheduler implements Scheduler { private final PluginManager pluginManager; private final ExecutorService taskService; private final ScheduledExecutorService timerExecutionService; - private final Multimap tasksByPlugin = Multimaps.synchronizedListMultimap( - Multimaps.newListMultimap(new IdentityHashMap<>(), ArrayList::new)); + private final Multimap tasksByPlugin = Multimaps.synchronizedMultimap( + Multimaps.newSetMultimap(new IdentityHashMap<>(), HashSet::new)); public VelocityScheduler(PluginManager pluginManager) { this.pluginManager = pluginManager; From b7725a7764215b33382c502634a48bb647dc0cd9 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 28 Aug 2018 21:27:03 -0400 Subject: [PATCH 2/3] More sane shutdown code. --- .../velocitypowered/proxy/scheduler/VelocityScheduler.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java b/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java index 3e87ab911..6e10807e3 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java @@ -12,6 +12,7 @@ import com.velocitypowered.api.scheduler.TaskStatus; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.Collection; import java.util.HashSet; import java.util.IdentityHashMap; import java.util.concurrent.*; @@ -41,7 +42,11 @@ public class VelocityScheduler implements Scheduler { } public boolean shutdown() throws InterruptedException { - for (ScheduledTask task : ImmutableList.copyOf(tasksByPlugin.values())) { + Collection terminating; + synchronized (tasksByPlugin) { + terminating = ImmutableList.copyOf(tasksByPlugin.values()); + } + for (ScheduledTask task : terminating) { task.cancel(); } timerExecutionService.shutdown(); From 182c117dc502bfb488d217a21df812ec2a14b80d Mon Sep 17 00:00:00 2001 From: Leymooo Date: Thu, 30 Aug 2018 14:34:30 +0300 Subject: [PATCH 3/3] Shutdown logger to flush queue before call a System#exit --- .../java/com/velocitypowered/proxy/VelocityServer.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 13fccef60..d3f8cc295 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -50,6 +50,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; public class VelocityServer implements ProxyServer { + private static final Logger logger = LogManager.getLogger(VelocityServer.class); public static final Gson GSON = new GsonBuilder() .registerTypeHierarchyAdapter(Component.class, new GsonComponentSerializer()) @@ -116,10 +117,12 @@ public class VelocityServer implements ProxyServer { if (!configuration.validate()) { logger.error("Your configuration is invalid. Velocity will refuse to start up until the errors are resolved."); + LogManager.shutdown(); System.exit(1); } } catch (IOException e) { logger.error("Unable to load your velocity.toml. The server will shut down.", e); + LogManager.shutdown(); System.exit(1); } @@ -192,7 +195,9 @@ public class VelocityServer implements ProxyServer { } public void shutdown() { - if (!shutdownInProgress.compareAndSet(false, true)) return; + if (!shutdownInProgress.compareAndSet(false, true)) { + return; + } logger.info("Shutting down the proxy..."); for (ConnectedPlayer player : ImmutableList.copyOf(connectionsByUuid.values())) {