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][csharp-netcore] C# Client for Net Core generate port exaustion

See original GitHub issue
Description

I moved from Net Framework 4.7 to Net Core 3.1 and 5 and I have a critical issue.

The csharp-netcore client uses RestSharp and is not stable with Net Core actually. See this issue. It seems to be a net core breaking change they won’t patch in time and actually this is impacting on RestSharp.

It silently open at every call a new socket, creating a new HttpWebRequest each time. This is a behavior totally different in NetFramework where it keep the same. You can reproduce it easily generating a simple client and using it in both verisons. Test multiple calls and watch the connection in Wireshark, I can further add images or a report if you prefer.

While NetFramework honors the keep-alive header (supported also by the server) in Net Core it doesnt.

  • In NetFramework it do the handshake and TLS connection just 1 time, and it consumes just one socket keeping working on it with the next calls.
  • In Net Core not, it open a new socket each times.

This is critical because you cannot understand it when moving your client to net core until you have a feedback from the server closing the connections to all.

I see there is a version with HttpClient, i tried it but it create every time: var handler = new HttpClientHandler(); var client = new HttpClient();

openapi-generator version

openapi-generator-cli-5.1.0.jar with csharp-netcore client without settings.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Blackclawscommented, Mar 25, 2021

Pull request is up which fixes this issue

1reaction
Blackclawscommented, Mar 25, 2021

You are absolutely right. The issue is that HttpClient is not disposed. Will fix immediately. There is also the additional property reUseHttpClient which should alleviate the problem as only a single HttpClient is used for the whole ApiClient then.

Passing in an HttpClient is on the roadmap.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NET 6 Port exhaustion when using HttpClient in factory class
You are basically creating a new factory every time a message arrives, which causes the original problem. Try: builder.Services.
Read more >
Help with .net Core and port exhaustion : r/csharp - Reddit
We are doing load tests and after a few minutes the request per seconds will just drop. We are using Jmeter to generate...
Read more >
How do I prevent SNAT port exhaustion caused by server-side ...
I have an app built using the ASP.NET Core Angular spa template (https://docs.microsoft.com/en-us/aspnet/core/client-side/spa/angular) with ...
Read more >
How to automatically choose a free port in ASP.NET Core 3.0
Press Ctrl+C to shut down. Alternatively, instead of binding to the loopback address, you can bind to any IP address (using a random...
Read more >
IHttpClientFactory In .NET Core To Avoid Socket Exhaustion
So we can execute api and console client together: Also, this Web API runs on a specific port, you can check it under ......
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