msgpack-cli icon indicating copy to clipboard operation
msgpack-cli copied to clipboard

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

Open pariventhan opened this issue 4 years ago • 1 comments

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)

pariventhan avatar Jun 02 '20 08:06 pariventhan

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.

yfakariya avatar Jul 20 '20 11:07 yfakariya