question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] SDK creates a lot of HttpClient causing connection starvation

See original GitHub issue

Describe the bug When using the SDK for long-running processes, we’ve noticed that it’s causing Linux workloads to run out of connections (https://github.com/tomkerkhove/promitor/issues/798).

After digging deeper, we thought we were not using the SDK correctly so we’ve POCed a refactoring where we only authenticate once and re-use it for the rest of the processing (https://github.com/tomkerkhove/promitor/pull/844).

After digging deeper, @maartenba found that the SDK is creating a lot of HttpClients and not re-using them.

Is this on purpose or is this a bug?

Exception or Stack Trace

System.Net.Http.HttpRequestException: Too many open files in system ---> System.Net.Sockets.SocketException: Too many open files in system
   at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
   at System.Net.Sockets.DualSocketMultipleConnectAsync..ctor(SocketType socketType, ProtocolType protocolType)
   at System.Net.Sockets.Socket.ConnectAsync(SocketType socketType, ProtocolType protocolType, SocketAsyncEventArgs e)
   at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)

To Reproduce Steps to reproduce the behavior:

  • Authenticate client
  • Have look how many clients are created

Expected behavior Re-use of one HttpClient rather than 70+

Setup (please complete the following information):

  • OS: Linux
  • IDE : Visual Studio
  • Version of the Library used: 1.30.0

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:27 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
tomkerkhovecommented, Apr 22, 2020

No problem, take your time! Happy to wait for a good fix rather than rushing to regret it later on!

/cc @adam-resdiary

1reaction
AlexGhiondeacommented, Mar 25, 2020

@erich-wang do you have an update here?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] SDK creates a lot of HttpClient causing connection ...
After digging deeper, @maartenba found that the SDK is creating a lot of HttpClients and not re-using them. Is this on purpose or...
Read more >
HttpClient GetAsync ThreadPool Starvation
The biggest problem I see with this code is the Decompress<T> method which blocks on an async operations using Task.Result .
Read more >
You're using HttpClient wrong and it is destabilizing your ...
I've been using HttpClient wrong for years and it finally came back to bite me. My site was unstable and my clients furious,...
Read more >
You're (probably still) using HttpClient wrong and it is ...
I try to optimize the fetching and deserialization of data in dotnet core as much as possible. HttpClientFactory and streams are my best ......
Read more >
HttpClient Connection Pooling in .NET Core - Code with Steve
In this issue, it was acknowledged that re-using a single HttpClient instance would result in connections remaining open indefinitely and as a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found