Skip to content

HttpClient created by BaseGraphRequestAdapter is never disposed #3132

@dimbleby

Description

@dimbleby

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_

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:waiting-for-triageAn issue that is yet to be reviewed or assignedtype:bugA broken experience

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions