Skip to content

Commit

Permalink
Don't call closeChannel on the Main Thread
Browse files Browse the repository at this point in the history
Using a listener will ensure the task of closing the connection is handled by a netty thread
  • Loading branch information
LXGaming authored and dualspiral committed Apr 29, 2020
1 parent 6a4e839 commit 8b9a239
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/org/spongepowered/common/util/NetworkUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.mojang.authlib.GameProfile;
import io.netty.buffer.Unpooled;
import io.netty.channel.local.LocalAddress;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
Expand Down Expand Up @@ -215,8 +217,13 @@ public static void initializeConnectionToPlayer(final PlayerList playerList, fin

try {
((PlayerListAccessor) playerList).accessor$getPlayerListLogger().info("Disconnecting " + (gameprofile != null ? gameprofile.toString() + " (" + netManager.getRemoteAddress().toString() + ")" : String.valueOf(netManager.getRemoteAddress() + ": " + reason.getUnformattedText())));
netManager.sendPacket(new SPacketDisconnect(reason));
netManager.closeChannel(reason);
netManager.sendPacket(new SPacketDisconnect(reason), new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
netManager.closeChannel(reason);
}
});
netManager.disableAutoRead();
} catch (Exception exception) {
((PlayerListAccessor) playerList).accessor$getPlayerListLogger().error("Error whilst disconnecting player", exception);
}
Expand Down

0 comments on commit 8b9a239

Please sign in to comment.