#2908: Don't frame packets for dead connections
This commit is contained in:
parent
a0f9333a13
commit
15b514130e
@ -14,6 +14,13 @@ public class LegacyDecoder extends ByteToMessageDecoder
|
|||||||
@Override
|
@Override
|
||||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
|
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() )
|
if ( !in.isReadable() )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -20,6 +20,13 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
|
|||||||
@Override
|
@Override
|
||||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
|
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;
|
Protocol.DirectionData prot = ( server ) ? protocol.TO_SERVER : protocol.TO_CLIENT;
|
||||||
ByteBuf slice = in.copy(); // Can't slice this one due to EntityMap :(
|
ByteBuf slice = in.copy(); // Can't slice this one due to EntityMap :(
|
||||||
|
|
||||||
|
@ -15,6 +15,16 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
|
|||||||
@Override
|
@Override
|
||||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
|
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();
|
in.markReaderIndex();
|
||||||
|
|
||||||
final byte[] buf = new byte[ 3 ];
|
final byte[] buf = new byte[ 3 ];
|
||||||
|
Loading…
Reference in New Issue
Block a user