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

System.IO.IOException: Unable to read data from the transport connection #1349

Closed
dyardyGIT opened this issue Aug 13, 2019 · 3 comments
Closed

Comments

@dyardyGIT
Copy link

dyardyGIT commented Aug 13, 2019

Using IIS, ASP.NET Core 2.2 and RestSharp V106.6.10 via Nuget on multiple servers getting exceptions after a period of time. My API calls with RestSharp work for a while then all of a sudden they start failing with common exception messages such as...

"ErrorException:System.Net.WebException: An error occurred while sending the request. Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"

This occurs on multiple servers and I have yet to determine the source of the issue.

I have tried to create RestClient per call and also as a singleton with the same exception in both cases. I have also tried using syncrhonously as well as async all the way from the controller to the server call. In all cases I continue to get the above failure messages after a period of time.

Restarting the apppool does not resolve the issue. The only thing that will resolve this is a server reboot. I believe it has something to do with http client connections and reaching some limit but have yet to determine why i continue to have this issue.

Any help would be greatly appreciated.

Code currently looks like...

            var defaultTimeout = 5 * 60 * 1000;
            _restClientTimeout = defaultTimeout;
            _restClientReadWriteTimeout = defaultTimeout;
            _requestTimeout = defaultTimeout;
            _client = new RestClient(_fastFieldBaseUrl);
            _client.Timeout = _restClientTimeout;
            _client.ReadWriteTimeout = _restClientReadWriteTimeout;

            var request = new RestRequest(url, Method.POST);
            request.Timeout = _requestTimeout;
            request.ReadWriteTimeout = _requestTimeout;
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("body", json, ParameterType.RequestBody);
            try
            {
                var response = await _client.ExecuteTaskAsync(request);
                if (response.StatusCode == HttpStatusCode.Created)
                {
                    return response.RawBytes;
                }
                else
                {
                    var message= $"ExecuteTaskAsync raw bytes is null                    GetResponseMessage(response)}";
                    Log(message, traceIdentifier, null, Microsoft.Extensions.Logging.LogLevel.Error);
                    return null;
                }
            }
            catch (Exception e)
            {
                var message = $"Error: {e.ToString()}";
                Log(message, traceIdentifier, e, Microsoft.Extensions.Logging.LogLevel.Error);
            }
@alexeyzimarev
Copy link
Member

Duplicate of #1322

@alexeyzimarev alexeyzimarev marked this as a duplicate of #1322 Aug 13, 2019
@dyardyGIT
Copy link
Author

I read other post, while very similar was there resolution?

@alexeyzimarev
Copy link
Member

@dyardyGIT I don't know one but there's no point to having two identical issues.

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

No branches or pull requests

2 participants