Skip to content

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

@kvantetore

Description

@kvantetore

Is there an existing issue for this?

  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesbugThis issue describes a behavior which is not expected - a bug.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions