microsoftgraph / microsoftgraph/msgraph-sdk-dotnet
`HttpClient` created by `BaseGraphRequestAdapter` is never disposed
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 789
- Forks
- 264
- Avg merge
- 15h 17m
- Merged PRs (30d)
- 3
Description
Describe the bug
When a GraphServiceClient is constructed without an externally‑supplied HttpClient, BaseGraphRequestAdapter eagerly creates one via GraphClientFactory.Create(...) and forwards it to the base Kiota HttpClientRequestAdapter.
Kiota records createdClient = false (because, from its perspective, the caller supplied the client), so HttpClientRequestAdapter.Dispose() never disposes it.
BaseGraphRequestAdapter does not override Dispose and does not retain a reference to clean up itself.
The HttpClient - together with its HttpMessageHandler and connection pool - is therefore leaked.
Wrapping the GraphServiceClient in using does not fix the leak: the dispose chain reaches Kiota, which deliberately skips the HttpClient because createdClient == false.
Expected behavior
Disposable resources should be disposed.
How to reproduce
just create a GraphServiceClient
var graph = new GraphServiceClient(cred, new[] { "https://graph.microsoft.com/.default" });
SDK Version
5.104.0
Latest version known to work for scenario above?
No response
Known Workarounds
supply your own HttpClient (and dispose of it yourself)
private readonly HttpClient _httpClient = GraphClientFactory.Create();
using var graph = new GraphServiceClient(_httpClient, credential, scopes);
Debug output
Click to expand log
```</details>
### Configuration
_No response_
### Other information
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading BaseGraphRequestAdapter and the GraphServiceClient construction path, especially where GraphClientFactory.Create(...) supplies the HttpClient to the Kiota adapter. Trace the disposal chain and verify that a client created internally, including its handler and connection pool, is released when the GraphServiceClient is disposed, while an externally supplied client remains caller-owned.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100