Skip to content

.NET Client - re-using default handlers causes ClientFactory.Build() to fail after any request has been issued #144

@caleblloyd

Description

@caleblloyd

The static handlers here are causing any call to ClientFactory.Build() to fail after a request on a previous built client has been issued:

private static readonly Lazy<List<DelegatingHandler>> s_handlers =
new(() =>
[
new APIVersionHandler(),
new UserAgentHandler(),
new RateLimitHandler(),
]);

The Kiota default handlers are created every time, so they get a new instance per client. But these 3 static handlers are re-used for every client, which results in the _operationStarted = true being set on the handler the first time any client has issued a request.

image

When ChainHandlersCollectionAndGetFirstLink is called, it attempts to set the InnerHandler on each handler in the chain:

image

This results in an exception, when trying to set the InnerHandler:

image

The exception is:

      System.InvalidOperationException: This instance has already started one or more requests. Properties can only be modified before sending the first request.
         at System.Net.Http.DelegatingHandler.CheckDisposedOrStarted()
         at System.Net.Http.DelegatingHandler.set_InnerHandler(HttpMessageHandler value)
         at GitHub.Octokit.Client.ClientFactory.ChainHandlersCollectionAndGetFirstLink(HttpMessageHandler finalHandler, DelegatingHandler[] handlers)
         at GitHub.Octokit.Client.ClientFactory.Build()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions