From f18e2b3875d9e300928859f06394126f96524f26 Mon Sep 17 00:00:00 2001 From: Juan Cruz Linsalata <25271111+linsaftw@users.noreply.github.com> Date: Sat, 24 Apr 2021 13:30:08 -0300 Subject: [PATCH] Cancel Bungee packet encoding when closed (#2448) --- .../ViaVersion/bungee/handlers/BungeeChannelInitializer.java | 4 ++++ .../myles/ViaVersion/bungee/handlers/BungeeDecodeHandler.java | 4 ++++ .../myles/ViaVersion/bungee/handlers/BungeeEncodeHandler.java | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeChannelInitializer.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeChannelInitializer.java index 2445bfe80..e0ce86a7b 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeChannelInitializer.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeChannelInitializer.java @@ -40,6 +40,10 @@ public class BungeeChannelInitializer extends ChannelInitializer { @Override protected void initChannel(Channel socketChannel) throws Exception { + if (!socketChannel.isActive()) { + return; + } + UserConnection info = new UserConnection(socketChannel); // init protocol new ProtocolPipeline(info); diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeDecodeHandler.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeDecodeHandler.java index 62003d98d..c6b3f0330 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeDecodeHandler.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeDecodeHandler.java @@ -37,6 +37,10 @@ public class BungeeDecodeHandler extends MessageToMessageDecoder { @Override protected void decode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List out) throws Exception { + if (!ctx.channel().isActive()) { + throw CancelDecoderException.generate(null); + } + if (!info.checkIncomingPacket()) throw CancelDecoderException.generate(null); if (!info.shouldTransformPacket()) { out.add(bytebuf.retain()); diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeEncodeHandler.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeEncodeHandler.java index 020cb2d85..334210e49 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeEncodeHandler.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeEncodeHandler.java @@ -39,6 +39,10 @@ public class BungeeEncodeHandler extends MessageToMessageEncoder { @Override protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List out) throws Exception { + if (!ctx.channel().isActive()) { + throw CancelEncoderException.generate(null); + } + if (!info.checkOutgoingPacket()) throw CancelEncoderException.generate(null); if (!info.shouldTransformPacket()) { out.add(bytebuf.retain());