Skip to content
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

Fix issue for HttpClient connection closed unexpectedly error after events submission. #207

Merged
merged 3 commits into from
Mar 15, 2019

Conversation

edwardmeng
Copy link
Contributor

We have encountered errors as following

2019-03-15 22:26:45.6781 Info  DefaultEventQueue: Sent 27 events to "https://log.mysite.com/".
2019-03-15 22:26:55.6419 Error DefaultEventQueue: An error occurred while submitting events.
2019-03-15 22:26:55.6439 Error System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: 基础连接已经关闭: 服务器关闭了本应保持活动状态的连接。 ---> System.IO.IOException: 无法从传输连接中读取数据: 远程主机强迫关闭了一个现有的连接。。 ---> System.Net.Sockets.SocketException: 远程主机强迫关闭了一个现有的连接。
   在 System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
   在 System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
   --- 内部异常堆栈跟踪的结尾 ---
   在 System.Net.Security._SslStream.EndRead(IAsyncResult asyncResult)
   在 System.Net.TlsStream.EndRead(IAsyncResult asyncResult)
   在 System.Net.PooledStream.EndRead(IAsyncResult asyncResult)
   在 System.Net.Connection.ReadCallback(IAsyncResult asyncResult)
   --- 内部异常堆栈跟踪的结尾 ---
   在 System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   在 System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
   --- 内部异常堆栈跟踪的结尾 ---
   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 Exceptionless.Submission.DefaultSubmissionClient.PostEvents(IEnumerable`1 events, ExceptionlessConfiguration config, IJsonSerializer serializer)
2019-03-15 22:26:55.6449 Info  DefaultEventQueue: Suspending processing for: 00:05:00.

The root cause is the http client requests will send header Connection:Keep-Alive.

Copy link
Member

@ejsmith ejsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... can you please tell me what this does and why we need it? I see that it instructs the HttpClient to close the connection and not use keep alive, but why would we want to need to do that?

@ejsmith ejsmith merged commit ab9987e into exceptionless:master Mar 15, 2019
@shamork
Copy link

shamork commented Jul 27, 2022

We should revert this commit, which can cause port exhausting problem.
Add a retry logic to fix System.Net.Http.HttpRequestException ( when connection is killed or reset unexpectly ).

@niemyjski
Copy link
Member

niemyjski commented Jul 27, 2022

@shamork do you have a link to more information about this? @edwardmeng did quite a bit of testing on this and we haven't had any issues reported since we've made this change and some clients are under extreme load.

@niemyjski
Copy link
Member

@shamork Are you currently running into this issue? Can you give us steps and criteria you are seeing this under? We made this change because we wanted more control over how connections were managed, All http submission happens on a background thread on a timer so it's not constant requests being made.

@ejsmith
Copy link
Member

ejsmith commented Jul 29, 2022

@shamork we are on a timer and send in batches so it's not constantly sending events. If I remember correctly, I looked at what MS was doing for App Insights client and they were doing the same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants