azure-libraries-for-net: [BUG] SDK creates a lot of HttpClient causing connection starvation

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

About this issue

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

Most upvoted comments

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

/cc @adam-resdiary

@erich-wang do you have an update here?

@erich-wang could you take a look?