Protobuf.net例外 - 超时在检查元数据 [英] Protobuf.net Exception - Timeout while inspecting metadata

查看:351
本文介绍了Protobuf.net例外 - 超时在检查元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的有时的尝试deserialise使用protobuf.net对象时,收到以下异常。我很惊讶,因为我从来没有比单个线程deserialising在同一时间同一对象和protobuf.net源似乎并没有使用任何静态对象的deserialising更多。该例外情况提出一个解决方案,但我不能确定如何实现这样会欢迎一个例子

I am sometimes receiving the following exception when attempting to deserialise an object using protobuf.net. I'm surprised as I never have more than a single thread deserialising the same object at the same time and the protobuf.net source does not seem to use any static objects for deserialising. The exception does suggest a solution but I am unsure as to how to implement so would welcome an example.

Base Exception Type:
System.TimeoutException: Timeout while inspecting metadata; this may indicate a deadlock. This can often be avoided by preparing necessary serializers during application initialization, rather than allowing multiple threads to perform the initial metadata inspection
at ProtoBuf.Meta.RuntimeTypeModel.TakeLock(Boolean& lockTaken)
at ProtoBuf.Meta.RuntimeTypeModel.FindOrAddAuto(Type type, Boolean demand, Boolean addWithContractOnly, Boolean addEvenIfAutoDisabled)
at ProtoBuf.Meta.RuntimeTypeModel.GetKey(Type type, Boolean demand, Boolean getBaseKey)

Inner Exception Type:
System.TimeoutException: Timeout while inspecting metadata; this may indicate a deadlock. This can often be avoided by preparing necessary serializers during application initialization, rather than allowing multiple threads to perform the initial metadata inspection
at ProtoBuf.Meta.RuntimeTypeModel.TakeLock(Boolean& lockTaken)
at ProtoBuf.Meta.RuntimeTypeModel.FindOrAddAuto(Type type, Boolean demand, Boolean addWithContractOnly, Boolean addEvenIfAutoDisabled)
at ProtoBuf.Meta.RuntimeTypeModel.GetKey(Type type, Boolean demand, Boolean getBaseKey)

Stack Trace: 
at ProtoBuf.Meta.RuntimeTypeModel.GetKey(Type type, Boolean demand, Boolean getBaseKey)
at ProtoBuf.Meta.TypeModel.GetKey(Type& type)
at ProtoBuf.Meta.TypeModel.Deserialize(Stream source, Object value, Type type)

问候,
马克

编辑补充:所以我定义我serialisable对象:

edit to add: I define my serialisable objects thus:

[ProtoContract]
public class Job
{
    [ProtoMember(1)]
    public long JobId { get; private set; } 
}



这将是我很难方便地调用PrepareSerialiser上的每一个我serialisable对象,因为我有不同的命名空间很多。不过想着它是什么,如果protobuf的被要求deserialise相同类型的两个对象发生的,一类是以前没有见过,在完全相同的时间?

It would be difficult for me to easily call PrepareSerialiser on each one of my serialisable objects as I have many in different namespaces. However thinking about it what happens if protobuf is asked to deserialise two objects of the same type, a type it has not seen before, at exactly the same time?

推荐答案

RuntimeTypeModel.Default(默认模式)是静态的,支撑静态序列化器类(重的评价是,没有任何静态)。尽管增加这个检查,由于偏执狂,我的从不看到这个错误引发。我绝对乐意看到将瑞普这样的例子。你确定你是不是线程?如果没有线程,我只能纳闷:是类型模型实在的真正的大

RuntimeTypeModel.Default (the default model) is static, and underpins the static Serializer class (re the comment that there wasn't any static state). Despite adding this check due to paranoia, I have never seen this error raised. I would absolutely love to see an example that will repro this. Are you sure you aren't threading? If not for threading, I can only wonder: is the type-model really really big?

事实上,即使有许多线程击中它积极在启动时(即在这里计算器),它很乖。由于错误信息提示,您可以尝试应用程序,启动过程中调用Serializer.PrepareSerializer,这将预先初始化的一切,避免任何线程的担忧。

Indeed, even with many threads hitting it aggressively at startup (i.e. here on stackoverflow) it is well behaved. As the error message hints, you might try calling Serializer.PrepareSerializer during app-startup, which will pre-initialize everything, avoiding any threading concerns.

但是,嘿!至少它没有发生死锁!

But hey! At least it didn't deadlock!

在这里奇怪的事情,虽然是它的还是不该 T为的可能的死锁 - 它故意用粗锁,以避免需要锁定顺序问题。再次 - 我真的很想看到一个样本

The odd thing here, though, is that it still shouldn't be possible to deadlock - it deliberately uses a coarse lock to avoid issues from the order it takes lock. Again - I'd really love to see a sample.

这篇关于Protobuf.net例外 - 超时在检查元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆