Correctly reset offset when fail lazy because of too long frame. (#8257)
Motivation: We need to reset the offset to 0 when we fail lazy because of a too long frame. Modifications: - Reset offset - Add testcase Result: Fixes https://github.com/netty/netty/issues/8256.
This commit is contained in:
parent
379a56ca49
commit
dc1b511fcf
@ -137,6 +137,8 @@ public class LineBasedFrameDecoder extends ByteToMessageDecoder {
|
||||
} else {
|
||||
discardedBytes += buffer.readableBytes();
|
||||
buffer.readerIndex(buffer.writerIndex());
|
||||
// We skip everything in the buffer, we need to set the offset to 0 again.
|
||||
offset = 0;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -185,4 +185,27 @@ public class LineBasedFrameDecoderTest {
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotFailFast() throws Exception {
|
||||
EmbeddedChannel ch = new EmbeddedChannel(new LineBasedFrameDecoder(2, false, false));
|
||||
assertFalse(ch.writeInbound(wrappedBuffer(new byte[] { 0, 1, 2 })));
|
||||
assertFalse(ch.writeInbound(wrappedBuffer(new byte[]{ 3, 4 })));
|
||||
try {
|
||||
ch.writeInbound(wrappedBuffer(new byte[] { '\n' }));
|
||||
fail();
|
||||
} catch (TooLongFrameException expected) {
|
||||
// Expected once we received a full frame.
|
||||
}
|
||||
assertFalse(ch.writeInbound(wrappedBuffer(new byte[] { '5' })));
|
||||
assertTrue(ch.writeInbound(wrappedBuffer(new byte[] { '\n' })));
|
||||
|
||||
ByteBuf expected = wrappedBuffer(new byte[] { '5', '\n' });
|
||||
ByteBuf buffer = ch.readInbound();
|
||||
assertEquals(expected, buffer);
|
||||
expected.release();
|
||||
buffer.release();
|
||||
|
||||
assertFalse(ch.finish());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user