From 567582b2e2acc1d374bb7780eea8213d63973f9b Mon Sep 17 00:00:00 2001 From: Hugo Manrique Date: Mon, 4 Oct 2021 21:17:36 +0200 Subject: [PATCH] Fix thread-unsafe command unregistration (#583) Access to the dispatcher is guarded by `lock`. --- .../proxy/command/VelocityCommandManager.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java index 45c259d8d..3d436980d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java @@ -143,9 +143,14 @@ public class VelocityCommandManager implements CommandManager { @Override public void unregister(final String alias) { Preconditions.checkNotNull(alias, "alias"); - // The literals of secondary aliases will preserve the children of - // the removed literal in the graph. - dispatcher.getRoot().removeChildByName(alias.toLowerCase(Locale.ENGLISH)); + lock.writeLock().lock(); + try { + // The literals of secondary aliases will preserve the children of + // the removed literal in the graph. + dispatcher.getRoot().removeChildByName(alias.toLowerCase(Locale.ENGLISH)); + } finally { + lock.writeLock().unlock(); + } } /**