Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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