microsoftgraph / microsoftgraph/msgraph-sdk-dotnet

`HttpClient` created by `BaseGraphRequestAdapter` is never disposed

Open
#3,132 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status:waiting-for-triage type:bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.