Skip to content

Reuse HttpClient #3

Description

@bronumski

The current implementation creates a new HttpClient for each request. This could eventually lead to all the available network sockets being consumed on the host machine in a heavily used environment.

https://github.com/mavezeau/TeamCitySharp/blob/master/src/TeamCitySharp/Connection/TeamCityCaller.cs#L250

The HttpClient is intended to be long lived with a single instance being reused for the lifetime of the application.

https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/
https://blogs.msdn.microsoft.com/shacorn/2016/10/21/best-practices-for-using-httpclient-on-services/
You will find similar items on StackOverflow

Simple fix here might be to create the HttpClient once when calling the create method for the first time and then reissue the same client on subsequent calls (may need to think about multiple threads).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions