Skip to content

MessagePackSerializer.DeserializeAsync blocks for a complete read #2229

@znakeeye

Description

@znakeeye

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:

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; }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions