#3746, #3666: Fix potential race conditions when connecting to multiple servers at the same time

This commit is contained in:
Valentine 2024-10-06 10:55:12 +03:00 committed by GitHub
parent 01a5f36012
commit 9813e46e66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View File

@ -361,7 +361,10 @@ public class ServerConnector extends PacketHandler
if ( user.getServer() != null ) if ( user.getServer() != null )
{ {
// Begin config mode // Begin config mode
if ( user.getCh().getEncodeProtocol() != Protocol.CONFIGURATION )
{
user.unsafe().sendPacket( new StartConfiguration() ); user.unsafe().sendPacket( new StartConfiguration() );
}
} else } else
{ {
LoginResult loginProfile = user.getPendingConnection().getLoginProfile(); LoginResult loginProfile = user.getPendingConnection().getLoginProfile();

View File

@ -306,6 +306,11 @@ public final class UserConnection implements ProxiedPlayer
{ {
Preconditions.checkNotNull( request, "request" ); Preconditions.checkNotNull( request, "request" );
ch.getHandle().eventLoop().execute( () -> connect0( request ) );
}
private void connect0(final ServerConnectRequest request)
{
final Callback<ServerConnectRequest.Result> callback = request.getCallback(); final Callback<ServerConnectRequest.Result> callback = request.getCallback();
ServerConnectEvent event = new ServerConnectEvent( this, request.getTarget(), request.getReason(), request ); ServerConnectEvent event = new ServerConnectEvent( this, request.getTarget(), request.getReason(), request );
if ( bungee.getPluginManager().callEvent( event ).isCancelled() ) if ( bungee.getPluginManager().callEvent( event ).isCancelled() )
@ -315,10 +320,6 @@ public final class UserConnection implements ProxiedPlayer
callback.done( ServerConnectRequest.Result.EVENT_CANCEL, null ); callback.done( ServerConnectRequest.Result.EVENT_CANCEL, null );
} }
if ( getServer() == null && !ch.isClosing() )
{
throw new IllegalStateException( "Cancelled ServerConnectEvent with no server or disconnect." );
}
return; return;
} }