Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pariventhan opened this issue Jun 2, 2020 · 1 comment
Labels
need-help Need help of experts to solve this issue

Comments

@pariventhan
Copy link

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)
@yfakariya yfakariya added the need-help Need help of experts to solve this issue label Jul 20, 2020
@yfakariya
Copy link
Member

Thank you for feedback and sorry for delayed response.

I recognized that packer wrote broken binary because of the exception. I think it is important for logging to have error resistance unpacking, but I have no good idea for it now. I guess we cannot detect broken range automatically.

It is welcome to discuss the solution, or point out my misunderstanding. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-help Need help of experts to solve this issue
2 participants