asp.net-core - 一个对象句柄有这么多 TimerQueueTimer 引用是什么意思
问题描述
我有一个应用程序,我怀疑其中存在内存泄漏。不仅在堆中,而且在我看来,对于我的应用程序发出的每个请求,整个工作集都在增长。我正在尝试根据这些说明对其进行调试,但我很难解释我看到的内容。我正在使用该dotnet-dump
工具分析转储。
总而言之,DocumentClient
如果我正确解释它,我有 618 个实例。当然,这将在字符串、字节数组等中添加大量数据。
Statistics:
MT Count TotalSize Class Name
00007f853c355110 618 187872 Microsoft.Azure.Cosmos.DocumentClient
这是从文档客户端的方法表中获取的单个引用的片段。请参阅 pastebin 以获取完整参考。它持续了 1200 多行,主要是TimerQueueTimer
参考。
00007F85AF2F10D8 (strong handle)
-> 00007F84C80FBAD8 System.Object[]
-> 00007F84C80FBB00 System.Threading.ThreadLocal`1+LinkedSlotVolatile[[System.Collections.Concurrent.ConcurrentBag`1+WorkStealingQueue[[System.IDisposable, System.Private.CoreLib]], System.Collections.Concurrent]][]
-> 00007F84C80FBB40 System.Threading.ThreadLocal`1+LinkedSlot[[System.Collections.Concurrent.ConcurrentBag`1+WorkStealingQueue[[System.IDisposable, System.Private.CoreLib]], System.Collections.Concurrent]]
-> 00007F84C80FBB70 System.Collections.Concurrent.ConcurrentBag`1+WorkStealingQueue[[System.IDisposable, System.Private.CoreLib]]
-> 00007F84C80FBBB0 System.IDisposable[]
-> 00007F84C80FBA90 System.Diagnostics.DiagnosticListener+DiagnosticSubscription
-> 00007F84C80FAF30 Microsoft.ApplicationInsights.AspNetCore.DiagnosticListeners.HostingDiagnosticListener
-> 00007F84C80EB450 Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration
-> 00007F84C80D5688 Microsoft.ApplicationInsights.Extensibility.Implementation.ApplicationId.ApplicationInsightsApplicationIdProvider
-> 00007F84C80D5A60 Microsoft.ApplicationInsights.Extensibility.Implementation.ApplicationId.ProfileServiceWrapper
-> 00007F84C80D5A88 System.Net.Http.HttpClient
-> 00007F84C80D5AD0 System.Net.Http.HttpClientHandler
-> 00007F84C80D5B00 System.Net.Http.SocketsHttpHandler
-> 00007F84D80D1018 System.Net.Http.RedirectHandler
-> 00007F84D80D1000 System.Net.Http.HttpConnectionHandler
-> 00007F84D80D0D38 System.Net.Http.HttpConnectionPoolManager
-> 00007F84D80D0F70 System.Threading.Timer
-> 00007F84D80D0FE8 System.Threading.TimerHolder
-> 00007F84D80D0F88 System.Threading.TimerQueueTimer
-> 00007F84C80533A0 System.Threading.TimerQueue
-> 00007F84D910F3C0 System.Threading.TimerQueueTimer
-> 00007F84D910EE58 System.Threading.TimerQueueTimer
-> 00007F84D910A680 System.Threading.TimerQueueTimer
我是否有 Application Insights 或 Cosmos 内存泄漏?为什么有这么多TimerQueueTimer
参考文献?
解决方案
await Task.Delay
TimerQueueTimer
在每次通话时创建新的。
许多 TimerQueueTimer 表明有人await Task.Delay()
在循环中使用,而不是使用简单的new Timer()
.
-> Microsoft.Azure.Cosmos.Routing.GlobalEndpointManager+<StartRefreshLocationTimer>d__25
-> Microsoft.Azure.Cosmos.Routing.GlobalEndpointManager
看起来 Microsoft.Azure.Cosmos 的 GlobalEndpointManager使用 await Task.Delay 每次在 GlobalEndpointManager.cs 类的 StartRefreshLocationTimer 方法中引发异常
你可以在这里尝试几件事:
1)检查抛出了哪个异常以及如何避免它。
我猜这应该有助于记录异常:(
DefaultTrace.TraceSource.Listeners.Add(new System.Diagnostics.ConsoleTraceListener())
检查示例)
2) 确保ShouldRefreshEndpoints返回 false,如果它适合您的应用 :)
推荐阅读
- java - IBM Worklight Java HTTP 适配器在身份验证期间抛出 UNEXPECTED_ERROR
- javascript - 当我试图循环一个对象时如何使用 .match() ?
- http - Nginx 请求从浏览器超时,但它通过邮递员或 curl 工作
- android - Visual Studio 2019 for Mac Android App Webview 不播放 Youtube 视频
- c# - Unity重启脚本未激活
- r-exams - R-exam mchoice:moodlePercent(frac)中的错误:不在moodle分数列表中的百分比
- vb.net - 为什么 TCP 发送超时似乎没有连接到任何东西?
- javascript - javascript中从文件夹字符串到正确文件夹结构的算法
- git - 对于已经被 git 跟踪的文件,我们可以提交更改而不将它们添加到 GIT 中吗
- python - 缺少 1 个必需的位置参数:“屏幕”