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

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

Open
caleblloyd opened this issue Dec 16, 2024 · 0 comments · May be fixed by #146

Comments

@caleblloyd
Copy link

caleblloyd commented Dec 16, 2024

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant