对象句柄具有如此多的 TimerQueueTimer 引用是什么意思?



我有一个应用程序,我怀疑其中内存泄漏。不仅在堆中,而且在我看来,对于向我的应用程序发出的每个请求,整个工作集都在增长。我正在尝试根据这些说明对其进行调试,但我很难解释我所看到的内容。我正在使用dotnet-dump工具来分析转储。

总而言之,如果我正确解释它,我有 618 个DocumentClient实例。当然,这将在字符串、字节数组等中增加大量数据。

Statistics:
MT                    Count    TotalSize Class Name
00007f853c355110      618       187872  Microsoft.Azure.Cosmos.DocumentClient

下面是从文档客户端的方法表中获取的单个引用的代码段。请参阅粘贴以获取完整参考。它继续 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

我是否有应用程序见解或 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 每次在 GlobalEndpointManager 的 StartRefreshLocationTimer 方法中抛出异常时都会使用 await Task.Delay.cs 类

您可以在此处尝试以下几种方法:

1( 检查抛出的异常以及如何避免它。

我猜这应该有助于记录异常:DefaultTrace.TraceSource.Listeners.Add(new System.Diagnostics.ConsoleTraceListener())(检查示例(

2(确保ShouldRefreshEndpoints返回false,如果它适用于你的应用程序:)

最新更新