kerryjiang / SuperSocket

SuperSocket is a light weight, cross platform and extensible socket server application framework.
Apache License 2.0
3.95k stars 1.15k forks source link

在消息接收是,通过TerminatorPipelineFilter解析协议,偶尔会出现如下错误,导致错误解析不了。 #526

Closed XuLinFei closed 3 years ago

XuLinFei commented 3 years ago

System.InvalidOperationException: End position was not reached during enumeration. at System.ThrowHelper.ThrowInvalidOperationException_EndPositionNotReached() at System.Buffers.SequenceReader1.IsNextSlow(ReadOnlySpan1 next, Boolean advancePast) at System.Buffers.SequenceReader1.TryReadTo(ReadOnlySequence1& sequence, ReadOnlySpan1 delimiter, Boolean advancePastDelimiter) at SuperSocket.ProtoBase.TerminatorPipelineFilter1.Filter(SequenceReader1& reader) at SuperSocket.Channel.PipeChannel1.ReaderBuffer(ReadOnlySequence1& buffer, SequencePosition& consumed, SequencePosition& examined) at SuperSocket.Channel.PipeChannel1.ReadPipeAsync(PipeReader reader)

XuLinFei commented 3 years ago

问题找到了,reader.TryReadTo(out ReadOnlySequence pack, terminatorSpan, advancePastDelimiter: false)这方法 在没有找到对应尾的时候并没有返回false,而是直接报错了,修改成

      try
        {
            if (!reader.TryReadTo(out ReadOnlySequence<byte> pack, terminatorSpan, advancePastDelimiter: false))
                return null;

            try
            {
                return DecodePackage(ref pack);
            }
            finally
            {
                reader.Advance(terminator.Length);
            }
        }
        catch (Exception e)
        {
            reader.Rewind(reader.CurrentSpanIndex);
            return null;
        }

就可以了,希望可以官方修改一下这个bug

chucklu commented 3 years ago

Please refer to https://github.com/dotnet/runtime/pull/276 What's the .net version you are using? .net core 3.0 or .net 5?

XuLinFei commented 3 years ago

netcore 3.0

chucklu commented 3 years ago

The bug was fixed in 3.1.3 according dotnet/runtime#276

XuLinFei commented 3 years ago

好的,谢谢。