Azure / Azure/azure-functions-host

DynamicFunctionAssemblyLoadContext keeps ScriptHosts from GC

Open
#3,894 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

Doing some memory-leak testing and found that the `DyanamicFunctionAssemblyLoadContext` keeps a reference (eventually) to a `ScriptHost`. Since `AssemblyLoadContext`s live for the scope of the process, this means that these ScriptHosts never go away.

We'll need a way to clean up these contexts when a host recycles, or use weak refs to these objects.

Repro:
- In VS, Debug WebHost locally, with Diagnostic Tools running. Point root to the CSharp sample.
- Touch `host.json` file several times, which will cause restarts.
- Take snapshot.
- In snapshot, look for `ScriptHost` instances.

Here's a sample root:
![image](https://user-images.githubusercontent.com/1089915/50029855-1fa0fc00-ffa9-11e8-8697-3a7fbdf91200.png)

Contributor guide

Open the contributing guide

Research direction

Start by locating DynamicFunctionAssemblyLoadContext and tracing how it retains ScriptHost instances. Reproduce the leak by running the WebHost against the CSharp sample, touching host.json several times, and inspecting Diagnostic Tools snapshots. Done means recycled ScriptHosts are no longer retained by these contexts and can be garbage-collected.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.