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

IAsyncDisposable support #3048

Open
yfakariya opened this issue Nov 24, 2023 · 2 comments
Open

IAsyncDisposable support #3048

yfakariya opened this issue Nov 24, 2023 · 2 comments

Comments

@yfakariya
Copy link

As described .NET documentation, developers expect that services (and function instances) should be disposed even when they only implement IAsyncDisposable. In fact, IServiceProvider
created from Microsoft.Extensions.DependencyInjection.ServiceCollection handles IAsyncDisposable, but Azure Function runtime does not. It leads resource leaks caused by objects which only implement IAsyncDisposable, including ServiceBusSender and ServiceBusReceiver of the Azure ServcieBus, they eventually causes receive link exhausion.

This issue is same as #2870, which was closed as "completed" but it was not solved.

Repro steps

  1. Implement IAsyncDisposable for your function class or your service class.
  2. Run function. DisposeAsync() of function isntances, transient services, and scoped services never be called.
  3. Shutdown function. DisposeAsync() of singleton services never be called.

Expected behavior

If functions and services implement IAsyncDisposable, their DisposeAsync() will be called in end of their lifetime.
If they also implement IDisposable, IAsyncDisposable.DisposeAsync() should be preferred.

Actual behavior

DisposeAsync() never be called.

Known workarounds

  • Avoid to store IAsyncDisposable objects to fields of function instances and their dependencies.
    • Note that singleton is not workaround because their DisposeAsync() should be called in graceful shutdown.
  • Use isolated worker for services. As far as I saw, isolated worker never dispose service instance even it implement IDisposable, so it is incomplete workaround.

Related information

  • Package version: Microsoft.NET.Sdk.Functions: 4.2.0

As far as I saw, following methods should be fixed. I am ready to create PR if my assumption is right.

There are many DI related classes in azure-functions-host repo, so it is OK to post issue if needed.

@bhagyshricompany
Copy link

Thanks for reporting pls share the app name,region,invoction id etc.

@yfakariya
Copy link
Author

I think it is not Azure resource specific. Is the actual Azure resource required to report SDK issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants