dotnet / dotnet/aspnetcore

DefaultActionDescriptorCollectionProvider never disposes the handle returned by ChangeToken.Change(...)

Open
#66,425 1 comment 0 reactions 0 assignees View on GitHub
area-mvc bug
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

I am trying to create a multi tenant application, where each tenant has its own ServiceProvider and niddleware Pipleine (delegating some objects to a "root" ServiceProvider). A part of the design is being able to spin up and down "tenants" without restarting the host. I (think I) have it mostly sorted, but noticed a considerable memory leak when creating and disposing SerivceProviders and middleware pipelines:

The root cause is that the handle returned by `ChangeToken.OnChange(...)` in `DefaultActionDescriptorCollectionProvider` is silently dropped instead of disposed along with the `DefaultActionDescriptorCollectionProvider`. This effectively ties the lifetime of `DefaultActionDescriptorCollectionProvider` to the lifetime of the `IWebHostEnvironment.WebRootFileProvider`.

### Expected Behavior

The handle returned by ChangeToken.OnChange should be disposed. `ActionEndpointDataSourceBase` already does this correctly. I have modeled my PR to match this implementation.

Making `DefaultActionDescriptorCollectionProvider` implement `IDisposable` will make it correctly disconnect from the file system watchers when the ServiceProvider is disposed.

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

11.0.100-preview.4.26210.111

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.