第 3 个消息帧的 RSocket Net pipereader.ReadAsync 被截断,导致 MessageFramePeek 方法出错

问题描述

我使用 RSocket.Net 作为 Java Spring Boot RSocket 服务器的网络客户端。服务器将报价消息发送回客户端。示例代码一直工作到第 3 条引用消息,该消息被截断。

RSocketProtocol.Handler.cs

    static public async Task Handler(irsocketProtocol sink,PipeReader pipereader,CancellationToken cancellation)
    {
        Logs.Enter();

        //The original implementation was a state-machine parser with resumability. It doesn't seem like the other implementations follow this pattern and the .NET folks are still figuring this out too - see the internal JSON parser discussion for how they're handling state machine persistence across async boundaries when servicing a Pipeline. So,this version of the handler only processes complete messages at some cost to memory buffer scalability.
        //Note that this means that the Pipeline must be configured to have enough buffering for a complete message before source-quenching. This also means that the downstream consumers don't really have to support resumption,so the interface no longer has the partial buffer methods in it.
        while (!cancellation.IsCancellationRequested)
        {
            var read = await pipereader.ReadAsync(cancellation);
            var buffer = read.Buffer;

第一条消息是这样的,缓冲区大小为 942

enter image description here

下一条消息类似。那么第 3 条消息要么是 5657 的太大了!!?

enter image description here

或者它在 165 时太小了

enter image description here

这会导致 MessageFramePeek 方法出错

static public (int Length,bool IsEndOfMessage) MessageFramePeek(ReadOnlySequence<byte> sequence) { var reader = new SequenceReader<byte>(sequence); return reader.TryRead(out byte b1) && reader.TryRead(out byte b2) && reader.TryRead(out byte b3) ? ((b1 << 8 * 2) | (b2 << 8 * 1) | (b3 << 8 * 0),true) : (0,false); }

UPDATE 我检查了服务器和客户端上的编码类型是 JSON,以便字符串不会与线路上的对象混合。仍然存在同样的问题。

UPDATE 如果 RSocket.Core 构建在网络标准或网络框架上,则会发生同样的问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)