Skip to content

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

Closed
@dyardyGIT

Description

@dyardyGIT

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);
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions