-
Notifications
You must be signed in to change notification settings - Fork 2.1k
FileSystemWatcher is not released properly (OutOfMemoryException) #7696
Comments
I think we need to dispose the changetoken that we get here when this singleton service is disposed: |
@kichalla, assigning this to you to investigate further. Thanks! |
Are you holding these converters in a static variable and referencing in each test setup's MvcOptions instance? Also curious what do you mean by |
In
MvcJsonOptionsConfigurer :
|
@Materix Could you try doing the following and see if it fixes the issue? Currently the suspect is Update your server setup like below: .ConfigureAppConfiguration((webHostBuilderContext, config) =>
{
// Capture the environment created by the builder so that we can dispose the
// file providers hanging off of it.
HostingEnvironment = webHostBuilderContext.HostingEnvironment;
config.AddJsonFile("config.json", false, true)
.AddJsonFile($"config.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true);
}) And in your test's dispose method, try doing the following: public void Dispose()
{
if (HostingEnvironment?.ContentRootFileProvider is PhysicalFileProvider contentPhysicalFileProvider)
{
contentPhysicalFileProvider.Dispose();
}
if (HostingEnvironment?.WebRootFileProvider is PhysicalFileProvider webRootPhysicalFileProvider)
{
webRootPhysicalFileProvider.Dispose();
}
TestServer?.Dispose();
} |
Yes, this fix the issue. Everything is disposed correctly. Actually I temporary solved this problem by cleaning out file providers collection for RazorEngine because I don't use it In Startup.cs:
|
Awesome. Thanks for the confirmation! Is it possible for you to give a simple repro for this issue. We do run our functional tests quite often and have never come across this kind of issue, so were wondering if you are doing anything different. |
I have created a repro for others to take a look at it: |
Actually we have circa 900 integration test, where 700 are based on single static instance of TestServer and remaining 200 are based on instantiating TestServer each time. We started rewriting our tests to server per test mainly because we want to have separate in-memory database for each test and decouple tests from each other (changes in one test were visible in others). The other root of the problem probably is that our database used in static instance of TestServer grows rapidly (due to bad test arrangement where we use other endpoints and we have audit logic so everything is saved) I see in your repo that the common scenario is to use single instance of TestServer for all tests. Is it possible to use different database with single TestServer instance (f.e. send name of db in header)? Is there any common practise to achieve this? (we started project on ASP.NET Core 1.0 and updating it) I uploaded our Startup, TestStartup and both base class for test classes |
Thanks for sharing the details!
👍 That's sounds like a valid scenario for your per test TestServer instance usage.
We don't use a single instance for all the tests actually. For example, we have the BasicWebSite which is tested by bunch of test classes BasicTests.cs, FiltersTest.cs etc.). In each of these classes we use Xunit's TestFixture way of doing setup of the TestServer only once per that class. One more usage you might find interesting is you can use different |
Closing this issue in favor of https://github.com/aspnet/Home/issues/3110 |
During integration tests I get OutOfMemoryException for few last tests. For each single test new WebHostBuilder and TestServer were created (so new dependency injection container). After investigation I found that MvcOptions and therefore JsonSerializerSettings are not garbage collected (I have some JsonConverters with reference to quite big configuration).
MvcOptions are hold by PageActionDescrtiptorProvider from Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
Preparing TestServer and Client
My test class properly disposed TestServer and HttpClient after each test.
The text was updated successfully, but these errors were encountered: