MessagePackSerializer.DeserializeAsync blocks for a complete read

未關閉
#2,229 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
csharp
領域
backend

研究方向

從 src/MessagePack/MessagePackSerializer.cs 第 346 行附近開始,使用此處描述的 112 位元組訊息,透過 DeserializeAsync 重現 .NET 8 用戶端/伺服器序列。追蹤完整物件是否已在下一次讀取串流之前被消費,並透過一個針對性的回歸測試驗證預期的回傳行為。

由索引模型根據 Issue 內容生成。

描述

MessagePack 3.1.4, targeting .NET 8.

I'm seeing a deadlock for a quite simple client/server solution. Basically it goes like this:

  1. Client writes message X (112 bytes): SerializeAsync
  2. Client reads (waits) for message Y (response to X): DeserializeAsync
  3. Server reads message X (112 bytes): DeserializeAsync - blocks in second call in while loop. See below!

So the server never exits the read call, not allowing it to write an answer to the client. While debugging, I identified the cause of this. See this line in MessagePackSerializer.DeserializeAsync:

https://github.com/MessagePack-CSharp/MessagePack-CSharp/blob/39e4a792100d19e7da6ed42ff12b3bc21aac28e8/src/MessagePack/MessagePackSerializer.cs#L346

There, the server has read 112 bytes but the loop takes it back to the stream.ReadAsync() call where it blocks.

Bug or not?
Is this expected behavior? I asked it to deserialize a message, and it got all bytes needed for it. What am I missing here?

The message sent (112 bytes written and 112 bytes read)

[MessagePackObject]
[Union(0, typeof(HelloMessage))]
// Additional unions...
public abstract class PipeMessage
{
    [Key(0)]
    public required Guid Id { get; init; }
}

[MessagePackObject]
public sealed class HelloMessage : PipeMessage
{
    [Key(1)]
    public required Guid SessionId { get; init; }
    
    [Key(2)]
    public required string Secret { get; init; }

    [Key(3)]
    public required int ProtocolVersion { get; init; }
}
主要語言
C#
星號
6.8k
分支
778
平均合併
22 小時 8 分鐘
30 天內合併 PR
2

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

MessagePack-CSharp/MessagePack-CSharp 的其他 Issue

查看 MessagePack-CSharp/MessagePack-CSharp 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。