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

Implicitly constructed BaseGraphRequestAdapter can't be disposed #1724

Closed
NickDarvey opened this issue Mar 15, 2023 · 1 comment · Fixed by #1815
Closed

Implicitly constructed BaseGraphRequestAdapter can't be disposed #1724

NickDarvey opened this issue Mar 15, 2023 · 1 comment · Fixed by #1815
Labels

Comments

@NickDarvey
Copy link

Is your feature request related to a problem? Please describe.
Two constructors of Microsoft.Graph.GraphServiceClient 1 create instances of Microsoft.Graph.BaseGraphRequestAdapter. Microsoft.Graph.BaseGraphRequestAdapter needs to be disposed because it inherits 2 from Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter which needs to dispose its System.Net.HttpClient 3.

Describe the solution you'd like
Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter is disposable, therefore Microsoft.Graph.BaseGraphRequestAdapter which inherits from the former is disposable, therefore Microsoft.Graph.GraphServiceClient which instantiates the former should be disposable, following the cascading disposable pattern 4.

Describe alternatives you've considered
Alternatively, the GraphServiceClient constructor overloads that implicitly create a BaseGraphRequestAdapter could be obsoleted, forcing the user to instantiate BaseGraphRequestAdapter and dispose of it directly.

Additional context
A workaround is to use the GraphServiceClient constructor overloads that accept a BaseGraphRequestAdapter, instantiating and disposing the BaseGraphRequestAdapter yourself.

Footnotes

  1. https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/82d4f5d4b7a8216e787f2b227e08019773f6cc02/src/Microsoft.Graph/GraphServiceClient.cs#L59-L78

  2. https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/blob/3708629f91bc314a30d07e349cf6205f8ed30b52/src/Microsoft.Graph.Core/Requests/BaseGraphRequestAdapter.cs#LL16C68-L16C68

  3. https://github.com/microsoft/kiota-http-dotnet/blob/58fb5f4ad6edbaf54dfe184fa2d3b8538bc558f2/src/HttpClientRequestAdapter.cs#L530-L538

  4. https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose#cascade-dispose-calls

@ghost ghost added the Needs: Triage label Mar 15, 2023
@andrueastman
Copy link
Member

Thanks for raising this @NickDarvey

Just to add here. Another alternative would be to probably do something like this.

if (graphClient.RequestAdapter is IDisposable disposable)
{
    disposable. Dispose();
}

@ghost ghost locked as resolved and limited conversation to collaborators May 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants