-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[BUG][csharp-netcore] C# Client for Net Core generate port exaustion #9060
Comments
The latest version of OpenAPI Generator v5.1.0 supports HttpClient (--library httpclient). Please give it a try. |
I see there is a version with HttpClient, i tried it but it create every time:
So the issue remains |
You'll want this pr once it's merged. You pass in the HttpClient, so you control it entirely. Note that it requires a bit of post processing, but here is a script for it, just edit the parameters to suite your needs. java -jar "../openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar" generate `
-g csharp-netcore `
-i "your-swagger-file.yml" `
-c generator-config.json `
-o output `
-t templates `
--library httpclient
$files = Get-ChildItem output -Recurse | Where-Object {-Not($_.PSIsContainer)}
foreach ($file in $files)
{
$content=Get-Content $file.PSPath
if (-Not($content)){
continue;
}
# if null reference types are enabled
$content=$content -replace '\?{3,4}', '?' # replace every three to four consecutive occurrences of '?' with a single one
# if null reference types are not enabled
# $content=$content.Replace("????", "?") # reference type
# $content=$content.Replace("???", "") # value type
Set-Content $file.PSPath $content
} |
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. |
After some further investigation the issue appears a bit larger as even a static HttpClient will break after some usage. I'll investigate and try to get a pull request up today. |
Pull request is up which fixes this 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.
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.
The text was updated successfully, but these errors were encountered: