SerializationException under high load
This issue tracks a non-root-caused issue whereby a SerializationException is thrown in the Message deserialization path, usually during header deserialization, when the system is under high load.
I don't know how to reproduce the issue.
Example 1
Unexpected token '185' introducing type specifier
Example 2
Exception trying to process 43634 bytes from endpoint xx.xx.xxx.xx:58094
Exc level 0: System.Runtime.Serialization.SerializationException: Attempt to read past the end of the input stream: CurrentPosition=20, n=1851879244, totalLength=523283
at Orleans.Serialization.BinaryTokenStreamReader.CheckLength(Int32 n, Int32& offset, Boolean& safeToUse)
at Orleans.Serialization.BinaryTokenStreamReader.CheckLength(Int32 n, Int32& offset)
at Orleans.Serialization.BinaryTokenStreamReader.ReadString()
at Orleans.Runtime.Message.HeadersContainer.Deserializer(Type expected, IDeserializationContext context)
at Orleans.Serialization.SerializationManager.DeserializeMessageHeaders(IDeserializationContext context)
at Orleans.Runtime.IncomingMessageBuffer.TryDecodeMessage(Message& msg)
at Orleans.Runtime.Messaging.IncomingMessageAcceptor.ReceiveCallbackContext.ProcessReceived(SocketAsyncEventArgs e)
Example 3
!!!!!!!!!! Exception deserializing message body Exc level 0: System.ArgumentException: Extended key field is not null in non-extended UniqueIdentifier.
at Orleans.Runtime.UniqueKey.ValidateKeyExt(String keyExt, UInt64 typeCodeData)
at Orleans.Runtime.UniqueKey.NewKey(UInt64 n0, UInt64 n1, UInt64 typeCodeData, String keyExt)
at Orleans.Serialization.BinaryTokenStreamReader.ReadUniqueKey()
at Orleans.Serialization.BinaryTokenStreamReader.TryReadSimpleType(Object& result, SerializationTokenType& token)
at Orleans.Serialization.SerializationManager.DeserializeInner(Type expected, IDeserializationContext context)
at AppEngine.Interfaces.States.OrleansCodeGenCti_Reg_Models_Models_ChildControlInformationSerializer.Deserializer(Type expected, IDeserializationContext context) in U:\Apps\App\src\AppEngine.Grains\obj\Release\AppEngine.Grains.orleans.g.cs:line 1064
at Orleans.Serialization.SerializationManager.DeserializeInner(Type expected, IDeserializationContext context)
at Orleans.Serialization.BuiltInTypes.DeserializeList[T](Type expected, IDeserializationContext context)
at Orleans.Serialization.SerializationManager.DeserializeInner(Type expected, IDeserializationContext context)
at AppEngine.Interfaces.States.OrleansCodeGenCti_Reg_Models_Models_FormSectionInformationSerializer.Deserializer(Type expected, IDeserializationContext context) in U:\Apps\App\src\AppEngine.Grains\obj\Release\AppEngine.Grains.orleans.g.cs:line 993
at Orleans.Serialization.SerializationManager.DeserializeInner(Type expected, IDeserializationContext context)
at AppEngine.Interfaces.OrleansCodeGenAppEngine.Interfaces_GrainMessages_ProcessModelMessageSerializer.Deserializer(Type expected, IDeserializationContext context) in U:\Apps\App\src\AppEngine.Interfaces\obj\Release\AppEngine.Interfaces.orleans.g.cs:line 4921
at Orleans.Serialization.SerializationManager.DeserializeInner(Type expected, IDeserializationContext context)
at Orleans.Serialization.BuiltInTypes.DeserializeInvokeMethodRequest(Type expected, IDeserializationContext context)
at Orleans.Serialization.SerializationManager.DeserializeInner(Type expected, IDeserializationContext context)
at Orleans.Serialization.SerializationManager.Deserialize(Type t, BinaryTokenStreamReader stream)
at Orleans.Runtime.Message.DeserializeBody(SerializationManager serializationManager, List`1 bytes)
cc @sujesharukil who experienced this error here +here +here
Try reproducing with very large messages (> 500KB) and high concurrency (concurrent messages)
We had same issue on 1.5.2. Some errors on client side looks like:
Reference with no referred object
Unexpected token 'Request' introducing type specifier
SerializationException: Unexpected token '115' introducing type specifier
We noticed, that our contracts are marked [Immutable] attribute. After remove it from contracts we haven't had any problem. May be it could help to reproduce the issue under high load systems.
I can confirm that this is a problem primarily under heavy load and with very large messages. We are seeing this when we are passing a list of objects or a list of strings (where the strings can be fairly large) over the wire under heavy load. The downside to this is that when this error happens, the call chain seems to hang and an imminent timeout will happen.
@sujesharukil, can you be more specific as to wat 'large' message and string its? Order of magnitude approximation would be sufficient.
4mb+, the data itself doesn't matter... as smaller list with similar data gets through without issues.
Interesting. We read from the network into a buffer with a default size of 128k. If a message is larger than that we'll grow the buffer until we have the entire message, then process it. For messages under 1mb we keep the buffer size at the size needed to read the largest message.
So for instance, if we're reading messages of size 100k, then we get a 600k message, from that point on, the buffer will remain large enough to read messages of size 600k.
For messages over 1mb, we don't retain the large buffer, but instead shrink it down to 1mb. It can grow again if another message over 1mb comes in, but after each message over 1mb we always shrink the networking buffer back down to 1mb.
So for instance, if we're reading messages of size 100k, then we get a 4mb message, the buffer will be grown to 4mb to process that message, but then be shrunk back down to 1mb, and from that point on, the buffer will remain large enough to read messages of 1mb in size. If another 4mb message comes in, it will be grown for that message, then shrunk back down to 1mb.
Since most systems don't send messages over 1mb in size, this logic probably doesn't get exercised much, so it's possible a bug exists here somewhere.
We should probably add a large message load test (4mb) to try to duplicate this, and also make the 1mb buffer limit (DEFAULT_MAX_SUSTAINED_RECEIVE_BUFFER_SIZE) configurable.
--
There is another potential source of this problem. I don't recall the exact logic, but in some cases I believe we don't copy data in buffers into blocks from the block pool on write. I think this was an optimization for large buffers assuming that by the time they got to the network serialization they were immutable. This may not be true for large buffers 'marked' immutable, which are actually not treaded by the application layer as immutable. In these cases, what is written to the network may be being corrupted. I've never been comfortable with this optimization, but am not convinced its 'wrong', only that it's dangerous as it assumes that data marked immutable is actually really being treated by the application layer -as- immutable.
Are these large objects marked as Immutable? If so, are you confident the data is not modified once passed to the grain call? Does the issue remain after removing the immutablity marker?
Hi,
We reach a same issue during some deserialization with an orlean client on Version 2.2.0 (an error with message Unexpected token '63' introducing type specifier) .
Do you have any update on this bug?
Thanks
@aJule are you sending large messages?
Fixed by #5920