首页 > 解决方案 > 一个对象句柄有这么多 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

https://pastebin.com/V8CNQjR7

我是否有 Application Insights 或 Cosmos 内存泄漏?为什么有这么多TimerQueueTimer参考文献?

标签: asp.net-core.net-core

解决方案


await Task.DelayTimerQueueTimer在每次通话时创建新的。

许多 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,如果它适合您的应用 :)


推荐阅读