Azure / DotNetty

DotNetty project – a port of netty, event-driven asynchronous network application framework
Other
4.09k stars 977 forks source link

RedisDecoder.cs got an out_of_memory exception #387

Closed slmgong closed 6 years ago

slmgong commented 6 years ago

sometimes my app got an out of memory exception when test redis program. when i debug the function DecodeBulkStringContent here

` bool DecodeBulkStringContent(IByteBuffer byteBuffer, ICollection output)

    {
        .......
        // chunked write.

        int toRead = Math.Min(this.remainingBulkLength, readableBytes);

        this.remainingBulkLength -= toRead;

        IByteBuffer buffer = byteBuffer.ReadSlice(toRead);

        output.Add(new BulkStringRedisContent((IByteBuffer)buffer.Retain()));

        return true;

    }`

Variable remainingBulkLength=0, but the readableBytes=1, and got a dead loop until out of memory, and now test byteBuffer.readByte() = 13, i don't know what happened, redis server send an wrong message or other ?

StormHub commented 6 years ago

Do you have some sort of message logging to see what came out of the redis? I have been using Redis for quite a while, haven't seen this so far.

caozhiyuan commented 6 years ago

@StormHub last time i say it on gitter . change the code same to java will ok .

if (readableBytes == 0 || this.remainingBulkLength == 0 && readableBytes < RedisConstants.EndOfLineLength)

slmgong commented 6 years ago

the test case will cause the error.

` DotNetty.Transport.Channels.Embedded.EmbeddedChannel embeddedChannel = new DotNetty.Transport.Channels.Embedded.EmbeddedChannel( new DotNetty.Codecs.Redis.RedisDecoder(), new DotNetty.Codecs.Redis.RedisBulkStringAggregator(), new DotNetty.Codecs.Redis.RedisArrayAggregator());

            string test = "*3\r\n$7\r\nmessage\r\n$16\r\nTd:demo_response\r\n$3\r\nabc\r";
            embeddedChannel.WriteInbound(test.Buffer());
            var r = embeddedChannel.ReadInbound<DotNetty.Codecs.Redis.Messages.ArrayRedisMessage>();
            embeddedChannel.WriteInbound("\n".Buffer());
            var r2 = embeddedChannel.ReadInbound<DotNetty.Codecs.Redis.Messages.ArrayRedisMessage>();`
StormHub commented 6 years ago

@vivid216 Cool, let me have a look at it first.