我已经有一段时间没有遇到这个 SemaphoreFullException 了。
总结.. 我在 IIS 7.5 上使用 ASP.NET v4.0 框架应用程序池(集成)托管了一个应用程序。 我正在使用 Windows 身份验证通过域 (isinrole) 对我的用户进行身份验证。
我看过关于此主题的所有其他线程,其中建议设置 Pooling = False。 我不想那样做,因为性能优势,我想继续使用池化。
我正在使用 Entity Framework 6 来查询数据库,并且我没有在用户代码中的任何位置“处理”dbcontext。 看起来问题出在 DbConnectionPool 代码中。
错误在任何给定时刻随机发生。应用程序是否正在使用并不重要。有时,由于这个问题 - 我必须重新启动 IIS,因为新用户停止获得身份验证。
到目前为止我尝试了什么:
- 检查是否正在处理数据库事务对象。
- 检查是否过早处置了 DBContext (ctx)。
- 检查应用程序构建(32/62 位)。在这种情况下 - 我在任何 CPU 模式下构建应用程序,我的服务器是 64 位的。
注意:在我的应用程序中,我主要使用 linq-to-EF 对象来查询数据库。
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()
在这方面的任何帮助将不胜感激。
最佳答案
在我的例子中,问题是我在调试时停止了应用程序。该应用程序正在进行大量异步调用。
因此,我通过命令提示符或 PowerShell 重置了我的 IIS 服务器:iisreset
,它成功了。
EDIT: Look at the @aaroncatlin comment for IIS Express
关于c# - 信号量异常 - 将指定的计数添加到信号量会导致它超过其最大计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30013179/