From bb129a3d0ba1b32fd77fad01727f4f2b305d8233 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 19 Apr 2020 03:39:15 -0400 Subject: [PATCH] Fix rare race condition with transitioning If the player unexpectedly disconnects after ServerConnectEvent is fired, but before the connection transitions to the new player, Velocity would throw an exception thinking the connection was not present. This is the correct behavior, but the behavior is very surprising. Instead we will double-check to ensure the connection has not been lost before we continue with transitioning to the new server. --- .../proxy/connection/backend/TransitionSessionHandler.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java index 6f32e7ad1..9bd6a35ff 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java @@ -82,6 +82,13 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { server.getEventManager() .fire(new ServerConnectedEvent(serverConn.getPlayer(), serverConn.getServer())) .whenCompleteAsync((x, error) -> { + // Make sure we can still transition (player might have disconnected here). + if (!serverConn.isActive()) { + // Connection is obsolete. + serverConn.disconnect(); + return; + } + // Strap on the ClientPlaySessionHandler if required. ClientPlaySessionHandler playHandler; if (serverConn.getPlayer().getMinecraftConnection().getSessionHandler()