Skip to content

PackAsync & UnpackAsync not working when passing data continuously using for loop c# #342

Description

@pariventhan

Hi,

I am using TcpListener to transfer data from client to Server, This is service writing early 1000 lines with 4000 chars in one minutes.

Once I connected with server, code passing 1000 calls to server. I am using msgPack to send the data.

When I send the data in sync it's working fine, but If i am using Async, after 2 item, the channel got break.
Following is the sample code, basically we are using this for application logging, so from the application we are passing log information using msgPack.

`using (var stream = _tcpClient.GetStream())
{

                            for (int itemCount = 0; itemCount < 1000; itemCount++)
                            {


                                try
                                {
                                    await _serializer.PackAsync(stream, logobj);
                                    //await stream.FlushAsync();
                                }
                                catch (Exception)
                                {

                                }
                            }
                       
                    }`

In the server code am getting below error

System.Runtime.Serialization.SerializationException: Unpacker is not in the array header at offset 0. The stream may not be array.
   at MsgPack.Serialization.SerializationExceptions.ThrowIsNotArrayHeader(Unpacker unpacker)
   at MsgPack.Serialization.EmittingSerializers.Generated.System_Tuple_3_System_Int32_System_Int32_System_String_Serializer2.UnpackFromAsyncCore(Unpacker , CancellationToken )
   at MsgPack.Serialization.MessagePackSerializer`1.UnpackFromAsync(Unpacker unpacker, CancellationToken cancellationToken)
   at MsgPack.Serialization.MessagePackSerializer`1.UnpackAsync(Stream stream, CancellationToken cancellationToken)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    need-helpNeed help of experts to solve this issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions