-
Notifications
You must be signed in to change notification settings - Fork 64
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
The .Net Agent alongside usage of HttpClient is causing Unknown Socket Error in the .Net runtime #897
Comments
@sliderhouserules Regarding to the usage of |
Hello @sliderhouserules, Sorry we still haven't gotten around to looking at this. This is still on our radar, and we will spend some time attempting to repro this in the next few weeks. Can you provide an update on you current thinking surrounding this issue? Do you still believe that New Relic is causing this issue to occur? I reviewed the issue you filed with Microsoft, and it sounds like they suspect a root cause related to File handle access? |
Yeah, I've been working with MS, but that root cause that they discovered for the other person that had a similar issue/symptoms isn't my issue, I don't think. When I remove all New Relic calls from my application, the errors go away. When I put the calls back in, the SocketException occurs. I will be able to get back to testing this and attempting to solve it soon, and would love your assistance. But for now, I am not able to do anything with this due to other higher priority items in my work queue. If you get to it in the meantime, I can try to provide more information as you need it. |
From @vuqtran88: The main drivers for this change are these issues #897, and #1202 that were reported. There weren’t definitive conclusions about whether or not using WebRequest directly caused these reported issues, but my recommendation is we should replace WebRequest with HttpClient. The reasons are: For development/testing purposes only: https://github.com/newrelic/newrelic-dotnet-agent/tree/use-httpclient-proto |
Jira CommentId: 124228 [~angelatan]'s comment above is a copy-paste of my standup status from yesterday morning. As of this morning, the only remaining known problem with using HTTPClient instead of WebRequest for agent->collector communications is the issue with SSL certificates in the integration tests that use the "MockNewRelic" facility. As detailed above, I have some ideas on how to fix this that I plan to try today. |
Jira CommentId: 125225 Update: I got the integration tests that use MockNewRelic to pass using the default development SSL certificate (see https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-dev-certs). CI updated to get the dev cert trusted before running integration tests. After doing this I was able to get a completely green CI run: https://github.com/newrelic/newrelic-dotnet-agent/actions/runs/3698709592 Remaining tasks: |
Jira CommentId: 125261 Linux integration testing results: Failed! - Failed: 8, Passed: 311, Skipped: 0, Total: 319, Duration: 1 h 4 m The 8 failures are explained by:
I'm satisfied that the agent's use of HTTPClient works on Linux as well as on Windows. |
Jira CommentId: 128176 Updating status: there is a PR in review for this bug. We still need to do performance testing before we can merge. We have not been able to get this done due to the holiday and resource limitations. We hope to get this done, merged and released soon. |
Jira CommentId: 129289 Status update: same as last week, but I have dedicated time this week to work on getting this one across the finish line. Performance testing and ad-hoc proxy testing will be necessary. |
Jira CommentId: 130647 Proxy testing update:
Based on these results, I'm concluding that proxy support is working as expected with the agent using HTTPClient instead of WebRequest. As a bonus, this testing shows pretty convincingly that the switch to HTTPClient is doing one of the things that we want and expect it to, which is reducing the number of connections created/destroyed by the agent as it operates. On the PR branch, the Squid proxy log for an agent running for several minutes (and therefore sending multiple data payloads to NR) looks like this: 04/Jan/2023:12:12:04 -0800 74917 ::1 TCP_TUNNEL/200 4153 CONNECT staging-collector.newrelic.com:443 - HIER_DIRECT/staging-collector.newrelic.com - On the current main branch, it looks like this: 04/Jan/2023:12:00:19 -0800 975 ::1 TCP_TUNNEL/200 4153 CONNECT staging-collector.newrelic.com:443 - HIER_DIRECT/staging-collector.newrelic.com - etc. |
Jira CommentId: 130561 Excellent work [~ahemsath]! Very thorough. |
Work has been completed on this issue. |
Description
We have a .Net 5/6 application that is experiencing an inordinate number of
SocketExceptions
. We use a Web API base template and implement background processing that interacts heavily with AWS resources. We are using New Relic functionality extensively throughout.Removing any and all calls to the New Relic Agent, and all New Relic instrumentation, has alleviated the issue almost completely.
We have an issue filed directly with Microsoft that details the issue here.
Expected Behavior
The NR .Net Agent should play nice with the usage of
HttpClient
and theIHttpClientFactory
and not contribute to, or causeSocketExceptions
deep in the .Net runtime.Troubleshooting or NR Diag results
We have gone through our code intensively to make sure we are properly using the
IHttpClientFactory
which uses pooling under the hood to correctly useHttpClient
/HttpRequestMessage
. This is able to be plugged into all of the AWS clients so they are using it properly as well. We have removed all (other) 3rd party libraries that we can determine do not properly use these patterns. The errors persist.Since we use New Relic extensively, we refrained from removing it. Until I found this. You are apparently using
WebRequest
, which has been deprecated and is recommended to not be used, as it is known to cause socket exhaustion andSocketExceptions
.Once we completely removed all calls to the agent, and any references to NR namespaces and projects, the problems have ceased. Several hours of load testing has confirmed this.
Steps to Reproduce
I don't have a sample application to share with you, I can only suggest that:
dotnet create webapi
) be createdIHostedService
s that:interacts with external web resources (using GETs, PUTs, and POSTs to match our use case)
properly uses either singleton
HttpClient
or theIHttpClientFactory
The above should reproduce the error. Test targeting both .Net 5 and 6 and you should see the errors increase in frequency with .Net 6.
Your Environment
Additional context
Again, reference this issue on the dotnet/runtime board for more detail. I can also answer questions directly here.
Please let me know what else I can do.
The text was updated successfully, but these errors were encountered: