Skip to content
This repository was archived by the owner on Nov 17, 2018. It is now read-only.
This repository was archived by the owner on Nov 17, 2018. It is now read-only.

Don't capture the ExecutionContext in Timers created for expiry #171

@davidfowl

Description

@davidfowl

Any lazy activation of timers will capture the ExecutionContext. Combining this with a lazy initialization of the HttpClient and the handler graph may end up holding onto AsyncLocals for longer than expected. This could end up looking like a memory leak.

Here's an example of the HttpContext being captured by the timer inside of the ActiveHandlerTrackingEntry's timer's ExecutionContext.

->  000001c2ef4e50e0 Microsoft.Extensions.Http.DefaultHttpClientFactory
->  000001c2ef4e5608 System.Collections.Concurrent.ConcurrentDictionary`2[[System.String, System.Private.CoreLib],[System.Lazy`1[[Microsoft.Extensions.Http.ActiveHandlerTrackingEntry, Microsoft.Extensions.Http]], System.Private.CoreLib]]
->  000001c2ef4e57b8 System.Collections.Concurrent.ConcurrentDictionary`2+Tables[[System.String, System.Private.CoreLib],[System.Lazy`1[[Microsoft.Extensions.Http.ActiveHandlerTrackingEntry, Microsoft.Extensions.Http]], System.Private.CoreLib]]
->  000001c2ef4e56a8 System.Collections.Concurrent.ConcurrentDictionary`2+Node[[System.String, System.Private.CoreLib],[System.Lazy`1[[Microsoft.Extensions.Http.ActiveHandlerTrackingEntry, Microsoft.Extensions.Http]], System.Private.CoreLib]][]
->  000001c2ef5345c0 System.Collections.Concurrent.ConcurrentDictionary`2+Node[[System.String, System.Private.CoreLib],[System.Lazy`1[[Microsoft.Extensions.Http.ActiveHandlerTrackingEntry, Microsoft.Extensions.Http]], System.Private.CoreLib]]
->  000001c2ef534578 System.Lazy`1[[Microsoft.Extensions.Http.ActiveHandlerTrackingEntry, Microsoft.Extensions.Http]]
->  000001c2ef5365f8 Microsoft.Extensions.Http.ActiveHandlerTrackingEntry
->  000001c2ef5367a0 System.Threading.Timer
->  000001c2ef536838 System.Threading.TimerHolder
->  000001c2ef5367b8 System.Threading.TimerQueueTimer
->  000001c2ef533470 System.Threading.ExecutionContext
->  000001c2ef533450 System.Threading.AsyncLocalValueMap+OneElementAsyncLocalValueMap
->  000001c2ef533420 Microsoft.Extensions.Logging.LoggerExternalScopeProvider+Scope
->  000001c2ef5333c8 Microsoft.AspNetCore.Hosting.Internal.HostingLoggerExtensions+HostingLogScope
->  000001c2ef5328c8 Microsoft.AspNetCore.Http.DefaultHttpContext

cc @benaadams

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions