Skip to content

Commit

Permalink
#3746, #3666: Fix potential race conditions when connecting to multip…
Browse files Browse the repository at this point in the history
…le servers at the same time
  • Loading branch information
BoomEaro authored Oct 6, 2024
1 parent 01a5f36 commit 9813e46
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion proxy/src/main/java/net/md_5/bungee/ServerConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,10 @@ private void cutThrough(ServerConnection server)
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();
Expand Down
9 changes: 5 additions & 4 deletions proxy/src/main/java/net/md_5/bungee/UserConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ public void connect(final ServerConnectRequest request)
{
Preconditions.checkNotNull( request, "request" );

ch.getHandle().eventLoop().execute( () -> connect0( request ) );
}

private void connect0(final ServerConnectRequest request)
{
final Callback<ServerConnectRequest.Result> callback = request.getCallback();
ServerConnectEvent event = new ServerConnectEvent( this, request.getTarget(), request.getReason(), request );
if ( bungee.getPluginManager().callEvent( event ).isCancelled() )
Expand All @@ -315,10 +320,6 @@ public void connect(final ServerConnectRequest request)
callback.done( ServerConnectRequest.Result.EVENT_CANCEL, null );
}

if ( getServer() == null && !ch.isClosing() )
{
throw new IllegalStateException( "Cancelled ServerConnectEvent with no server or disconnect." );
}
return;
}

Expand Down

1 comment on commit 9813e46

@andreasdc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the exception be removed?

Please sign in to comment.