#2908: Don't frame packets for dead connections

This commit is contained in:
Andrew Steinborn 2020-07-19 08:54:54 +10:00 committed by md_5
parent a0f9333a13
commit 15b514130e
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
3 changed files with 24 additions and 0 deletions

View File

@ -14,6 +14,13 @@ public class LegacyDecoder extends ByteToMessageDecoder
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
{
// See check in Varint21FrameDecoder for more details
if ( !ctx.channel().isActive() )
{
in.skipBytes( in.readableBytes() );
return;
}
if ( !in.isReadable() )
{
return;

View File

@ -20,6 +20,13 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
{
// See Varint21FrameDecoder for the general reasoning. We add this here as ByteToMessageDecoder#handlerRemoved()
// will fire any cumulated data through the pipeline, so we want to try and stop it here.
if ( !ctx.channel().isActive() )
{
return;
}
Protocol.DirectionData prot = ( server ) ? protocol.TO_SERVER : protocol.TO_CLIENT;
ByteBuf slice = in.copy(); // Can't slice this one due to EntityMap :(

View File

@ -15,6 +15,16 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
{
// If we decode an invalid packet and an exception is thrown (thus triggering a close of the connection),
// the Netty ByteToMessageDecoder will continue to frame more packets and potentially call fireChannelRead()
// on them, likely with more invalid packets. Therefore, check if the connection is no longer active and if so
// sliently discard the packet.
if ( !ctx.channel().isActive() )
{
in.skipBytes( in.readableBytes() );
return;
}
in.markReaderIndex();
final byte[] buf = new byte[ 3 ];