From 9813e46e66b540628479406b39515de3a83c3ccc Mon Sep 17 00:00:00 2001 From: Valentine <21033866+BoomEaro@users.noreply.github.com> Date: Sun, 6 Oct 2024 10:55:12 +0300 Subject: [PATCH] #3746, #3666: Fix potential race conditions when connecting to multiple servers at the same time --- proxy/src/main/java/net/md_5/bungee/ServerConnector.java | 5 ++++- proxy/src/main/java/net/md_5/bungee/UserConnection.java | 9 +++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index 82832865..90c5237c 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -361,7 +361,10 @@ public class ServerConnector extends PacketHandler if ( user.getServer() != null ) { // Begin config mode - user.unsafe().sendPacket( new StartConfiguration() ); + if ( user.getCh().getEncodeProtocol() != Protocol.CONFIGURATION ) + { + user.unsafe().sendPacket( new StartConfiguration() ); + } } else { LoginResult loginProfile = user.getPendingConnection().getLoginProfile(); diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 54842ca0..2359e864 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -306,6 +306,11 @@ public final class UserConnection implements ProxiedPlayer { Preconditions.checkNotNull( request, "request" ); + ch.getHandle().eventLoop().execute( () -> connect0( request ) ); + } + + private void connect0(final ServerConnectRequest request) + { final Callback callback = request.getCallback(); ServerConnectEvent event = new ServerConnectEvent( this, request.getTarget(), request.getReason(), request ); if ( bungee.getPluginManager().callEvent( event ).isCancelled() ) @@ -315,10 +320,6 @@ public final class UserConnection implements ProxiedPlayer callback.done( ServerConnectRequest.Result.EVENT_CANCEL, null ); } - if ( getServer() == null && !ch.isClosing() ) - { - throw new IllegalStateException( "Cancelled ServerConnectEvent with no server or disconnect." ); - } return; }