Ninject中的错误? [英] Bug in Ninject?
问题描述
就我是否有真正的错误以及是否存在真正的错误寻求建议,如何最好地解决它:
Looking for advice on whether I have a real bug or not and if it is, how to fix it best:
我有一个运行24/7的高度多线程的进程. Ninject在ThreadScope中提供的绑定中注入了一些对象.
I have a highly multi-threaded process that runs 24/7. There are a few objects that are injected with bindings provided in ThreadScope by Ninject.
随着该过程的负载不断增加,该过程开始崩溃的频率越来越高.事件日志中的错误消息是这样的:
As the load on the process has been ever increasing, the process started crashing more and more often. Error message in the event log was this:
> Framework Version: v4.0.30319 Description: The process was terminated
> due to an unhandled exception. Exception Info:
> System.NullReferenceException Stack: at
> **Ninject.Activation.Caching.GarbageCollectionCachePruner.PruneCacheIfGarbageCollectorHasRun(System.Object)**
> at System.Threading.ExecutionContext.runTryCode(System.Object) at
> System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode,
> CleanupCode, System.Object) at
> System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,
> System.Threading.ContextCallback, System.Object, Boolean) at
> System.Threading._TimerCallback.PerformTimerCallback(System.Object)
下载Ninject的源代码并进行谷歌搜索之后,无论是Ninject还是.NET框架,这似乎都是一个问题(取决于您听的人).
After downloading the source for Ninject and googling, it appears to be a somewhat of an issue either with Ninject or .NET framework (depending on whoever you listen).
看起来像绑定缓存的修剪正在尝试重新启动finally子句中已处置的计时器对象. 一年前曾尝试解决这种逻辑问题,但似乎还远远不够: http://groups.google.com/组/ninject/browse_frm/thread/cedf5d129120ee18/27119d7d3761eedd?tvc = 1#27119d7d3761eedd
Looks like Pruning of binding cache is attempting to restart a disposed timer object in the finally clause. There was an attempt to fix an issue with that logic a year ago, but it does not appear to have gone far enough: http://groups.google.com/group/ninject/browse_frm/thread/cedf5d129120ee18/27119d7d3761eedd?tvc=1#27119d7d3761eedd
Microsoft在此MSDN文章中解释了系统计时器的工作方式: http://msdn.microsoft.com/zh-CN/library/system.threading.timer.aspx
Microsoft explains how the System Timer works in this MSDN article: http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx
根据MSDN文章,GC有可能在调用TimerCallback之前清理了计时器对象.因此,重新启动"finally"子句中的计时器会导致崩溃.
According to MSDN article, it is possible that GC has cleaned up the timer object BEFORE the TimerCallback is called. Thus, restarting the timer in the "finally" clause causes a crash.
问题:如何在Ninject代码中解决此问题?在这种情况下,我是否应该忽略该错误?我应该创建一个新计时器吗?我还应该做点别的吗?我目前已经修改了代码以忽略该错误,以便可以使进程停止崩溃...但是担心这不是一个很好的解决方案,欢迎您提出任何建议.
Question: how do I fix this in the Ninject code? Should I simply ignore the error in such a case? Should I create a new timer? Should I do something else? I've currently modified the code to ignore the error so that I can simply stop my process from crashing... but fear it is not a great solution, any advice is appreciated.
相关文章: http://groups.google.com/group/ninject/browse_thread/thread/8cdf8362a41153c7
.NET 3.5 System.Timer的C#错误System.ObjectDisposedException:无法访问已处置的对象
推荐答案
2.2中有一个bug,当处理缓存(Ninject)时会导致争用条件.在3.0中已解决
There is a bug in 2.2 that causes a race condition when the cache (Ninject) is disposed. This is fixed in 3.0
通常,除非在运行时创建和处置内核,否则您应该不会看到任何问题-无论如何这都不是使用Ninject的好方法,应尽可能避免使用.这样,发生此问题的唯一情况应该是关机.
Normally, you shouldn't see any problems unless you are creating and disposing kernels during runtime- This isn't a good way to use Ninject anyway and should be avoided whenever possible. That way the only situation where this problem occurs should be on shutdown.
这篇关于Ninject中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!