--- a/net/minecraft/network/Varint21FrameDecoder.java
+++ b/net/minecraft/network/Varint21FrameDecoder.java
@@ -8,8 +8,20 @@
 import java.util.List;
 
 public class Varint21FrameDecoder extends ByteToMessageDecoder {
+    private final byte[] lenBuf = new byte[3]; // Paper
+    @Override
     protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) {
+        // Paper start - if channel is not active just discard the packet
+        if (!channelHandlerContext.channel().isActive()) {
+            byteBuf.skipBytes(byteBuf.readableBytes());
+            return;
+        }
+        // Paper end
         byteBuf.markReaderIndex();
+        // Paper start - reuse temporary length buffer
+        byte[] abyte = lenBuf;
+        java.util.Arrays.fill(abyte, (byte) 0);
+        // Paper end
         byte[] bs = new byte[3];
 
         for(int i = 0; i < bs.length; ++i) {
