信号量异常-将指定的计数添加到信号量将导致其超过其最大计数 [英] Semaphore exception - Adding the specified count to the semaphore would cause it to exceed its maximum count
问题描述
一段时间以来,我一直在遇到这个SemaphoreFullException.
I've been having this SemaphoreFullException for quiet some time.
总结一下. 我已经在带有ASP.NET v4.0框架应用程序池"(集成)的IIS 7.5上托管了一个应用程序. 我正在使用Windows身份验证通过域(isinrole)对我的用户进行身份验证.
To summarize.. I have hosted an application on IIS 7.5 with ASP.NET v4.0 framework Application Pool (integrated). I am using windows authentication to authenticate my users through domain (isinrole).
我已经看过该主题的所有其他主题,建议将Pooling = False设置为该主题. 我不想这样做,由于性能方面的优势,我想继续使用池.
I've seen all other threads on this topic, where it is suggested to set Pooling = False. I do not want to do that and I would like to keep on using pooling because of the performance benefits.
我正在使用Entity Framework 6来查询数据库,而没有在用户代码中的任何地方分发" dbcontext. 看来问题出在DbConnectionPool代码中.
I am using Entity Framework 6 to query the database and I am not "disposing" the dbcontext anywhere in user code. It looks like the issue is in the DbConnectionPool code.
该错误在任何给定时间随机发生.是否正在使用该应用程序都没有关系.有时候,由于这个问题-我必须重新启动IIS,因为新用户不再获得身份验证.
到目前为止我已经尝试过的:
What I've tried so far:
- 检查是否正在处置数据库事务对象.
- 检查是否已过早处置DBContext(ctx).
- 检查应用程序的构建(32/62位).在这种情况下-我在任何CPU模式下构建应用程序,并且我的服务器是64位.
注意:在我的应用程序中,我主要使用linq-to-EF对象来查询数据库.
Note: In my application, I've mostly used linq-to-EF objects to query the DB.
Exception: System.Threading.SemaphoreFullException
Message: Adding the specified count to the semaphore would cause it to exceed its maximum count.
StackTrace: at System.Threading.Semaphore.Release(Int32 releaseCount)
at System.Data.ProviderBase.DbConnectionPool.CleanupCallback(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()
在这方面的任何帮助将不胜感激.
Any help in this regard will be greatly appreciated.
推荐答案
I think that this may be a solution to the problem: http://www.davepaquette.com/archive/2013/03/27/managing-entity-framework-dbcontext-lifetime-in-asp-net-mvc.aspx - as you can see there, it is essential to take care for disposal of the DbContext when it´s lifetime is over.
请记住,Db连接最终以不受管的db处理代码结束,因此问题是除非垃圾回收将上下文保持在休眠状态,否则它将一直驻留在主内存中,从而也阻止了来自连接池的连接.因此,在适当的条件下,迟早要清空连接池并获取异常.
Remember, Db connections end up in unmanaged db handling code, so the problem is unless garbage collection disposes the context it stays sleeping in the main memory, thereby also blocking a connection from the connection pool. So sooner or later, under the right conditions, you empty the connection pool and get your exception.
这篇关于信号量异常-将指定的计数添加到信号量将导致其超过其最大计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!