Skip to content

remove handler cause ByteToMessageDecoder out disorder #9668

@switchYello

Description

@switchYello

remove handler cause ByteToMessageDecoder out disorder

I input byte stream [1,2,3,4,5], when i read `4` then remove  ByteToMessageDecoder,
 the out is stream [1,2,3,5,4]

Here are the test cases,the cases will fail
 @Test
    public void testDisorder(){
        ByteToMessageDecoder decoder = new ByteToMessageDecoder() {
            int count = 0;

            //read 4 byte then remove this decoder
            @Override
            protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
                out.add(in.readBytes(1));
                if (++count >= 4) {
                    ctx.pipeline().remove(this);
                }
            }
        };

        EmbeddedChannel channel = new EmbeddedChannel(decoder);
        assertTrue(channel.writeInbound(Unpooled.wrappedBuffer(new byte[]{1, 2, 3, 4, 5})));
        assertEquals(1, ((ByteBuf) channel.readInbound()).readByte());
        assertEquals(2, ((ByteBuf) channel.readInbound()).readByte());
        assertEquals(3, ((ByteBuf) channel.readInbound()).readByte());
        assertEquals(4, ((ByteBuf) channel.readInbound()).readByte());
        assertEquals(5, ((ByteBuf) channel.readInbound()).readByte());
        assertFalse(channel.finish());
    }


netty 4.1

java8

window10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions