-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Analyzer] Unawaited / returned tasks created with a disposable in using block for that disposable #78394
[Analyzer] Unawaited / returned tasks created with a disposable in using block for that disposable #78394
Comments
Tagging subscribers to this area: @dotnet/area-system-threading-tasks Issue DetailsConsider code like the following: public Task MyMethodAsync()
{
using (SomeIDisposable disposable = new SomeIDisposable())
{
...
return SomethingAsync(disposable);
}
} There's a high likelihood that this Task-returning SomethingAsync will be using the SomeIDisposable instance long after it's been disposed. We should consider an analyzer that flags such situations.
|
While it can't detect cases where the IDisposable got wrapped into another parameter, it does seem like it provides value for the ones it detected. It would also be nice if it could detect the dispose via a manual try-finally or direct imperative code (e.g. SomeIDisposable disposable = new SomeIDisposable();
Task t = SomethingAsync(disposable);
disposable.Dispose();
return t; ) And it might be further nice if we could generalize it to rent/return patterns like ArrayPool, but that's perhaps getting a bit fantastical (and each would require a custom flow analyzer, or putting some sort of attribute on IDisposable.Dispose() (and all aliasing Close() methods) and ArrayPool.Return) Category: Reliability |
I'd like to be assigned this for .NET 10 |
Great, thanks! |
Consider code like the following:
There's a high likelihood that this Task-returning SomethingAsync will be using the SomeIDisposable instance long after it's been disposed. We should consider an analyzer that flags such situations.
The text was updated successfully, but these errors were encountered: