Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IHost Memory leak with CreateDefaultBuilder #31219

Closed
CurtisFulton opened this issue Mar 25, 2021 · 3 comments
Closed

IHost Memory leak with CreateDefaultBuilder #31219

CurtisFulton opened this issue Mar 25, 2021 · 3 comments

Comments

@CurtisFulton
Copy link

Describe the bug

Stopping and disposing an instance of IHost leaves FileSystemWatchers, causing a small memory leak.
Seems to be related to the default configuration files it tries to watch.

To Reproduce

Using the Standard .Net 5 Console App template in Visual studio.

private static async Task Main(string[] args)
{
    var loopCount = 0;
    while (true)
    {
        loopCount++;
        using var host = Host.CreateDefaultBuilder()
                             .Build();

        await host.StartAsync();
        await host.StopAsync();

        GC.Collect();
        GC.WaitForPendingFinalizers();

        Console.WriteLine($"Completed loop {loopCount}");
    }
}

Running the above code, note the memory usage of the console app consistently goes up.
After ~15000 loops it was using ~200mb of memory.

Looking at the memory snapshot I can see there seems to be 1 FileSystemWatcher (And related things) stuck for every loop that occurs.

image

I found that clearing the config sources by running

ConfigureAppConfiguration(config =>
{
    config.Sources.Clear();
})

seemingly removes the issue. So I assume that the leak is coming from the setup of the default configuration.

@BrennanConroy
Copy link
Member

Looks like a dupe of #31125

@CurtisFulton
Copy link
Author

Didn't seem like it at first, but based on the pull request fixes it looks like it's the same issue.

Do I close this one or do they both stay open until it's fixed?

@BrennanConroy
Copy link
Member

Let's close this, if you think it's different we can reopen :)

@ghost ghost locked as resolved and limited conversation to collaborators Apr 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants