-
Notifications
You must be signed in to change notification settings - Fork 290
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
Do not create a new HttpClient for every Transmission #594
Comments
Thank you for reporting the issue. Feel free to send a PR. |
Not sure if I have time for it. Would you agree to this approach:
Does this need additional tests in TransmissionTest.cs? |
I'd say move it away from the transmission class and make HttpClient be owned by the sender. This way the lifecycle of a single HttpClient is much easier to control. And there will be no problems of one httpclient shared by multiple senders and attempts to send data the same time. |
I agree to that. However there's conditional |
@cwe1ss with the approach you proposed you'll need to synchronize access to static variable. Do you have an idea how to make it efficient? It may not be a huge refactoring if you'll keep some wrapper class in Sender that will be used by transmissions. |
HttpClient is thread safe if used correctly. You don't need to synchronize access to it, just its construction. Safe methods:
See https://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.110).aspx#Anchor_5 |
Thanks @kogir! It makes sense now to go with the simpler fix and just reuse a static |
Closing via #857 |
Remove signing from test projects
https://github.com/Microsoft/ApplicationInsights-dotnet/blob/develop/src/Core/Managed/Shared/Channel/Transmission.cs#L62 creates a new HttpClient instance for every transmission.
See e.g. https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/ for why this is wrong (it creates too many sockets and they stay open for too long).
The text was updated successfully, but these errors were encountered: