Skip to content

.NET SDK AmazonResourceExplorer2Client Search intermittent connection timeout

1

I am seeing intermittent connection timeout errors when using the AmazonResourceExplorer2Client's Search API via the .net SDK. This search works more often than not, when it does it finishes in a few seconds. Intermittently we will see a connection timeout with no real underlying reason for the error. CloudWatch logs show this same error with a stack trace and a number of retries, all ending in a timeout.

*** Using the AWSSDK.ResourceExplorer2 nuget package, version 3.7.402.24.

Here are the logs for the error:

2025-01-01T00:24:58.391Z 392a0a25-5034-421e-b4bd-cc61f6d6008b info AWSSDKUtils 17|2025-01-01T00:24:58.391Z|DEBUG|Double encoded /Search with endpoint https://resource-explorer-2.us-east-2.amazonaws.com/ for canonicalization: /Search

2025-01-01T00:25:44.891Z 392a0a25-5034-421e-b4bd-cc61f6d6008b info AmazonResourceExplorer2Client 18|2025-01-01T00:25:44.789Z|ERROR|An exception of type HttpRequestException was handled in ErrorHandler. --> System.Net.Http.HttpRequestException: Connection timed out (resource-explorer-2.us-east-2.amazonaws.com:443) ---> System.Net.Sockets.SocketException (110): Connection timed out at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(HttpRequestMessage request) at System.Threading.Tasks.TaskCompletionSourceWithCancellation1.WaitWithCancellationAsync(CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken) at Amazon.Runtime.Internal.HttpHandler1.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)

The pattern above is repeated numerous times until the task times out and the request is closed. We are also billed for all of the retries, 15 minutes of them.

*** As a side note, we also have seen similar connection timeout issues when using the AWSSDK.S3 and AWSSDK.SimpleSystemsManagement packages - very randomly when using the PutObjectAsync() and SendCommandAsync() methods, respectively.

2 Answers
0

Greeting

Hi Karl,

Thank you for reaching out about the intermittent connection timeouts you’re experiencing with the AmazonResourceExplorer2Client Search API. I can sense the frustration these issues are causing, especially when compounded by billing costs for retries. Let’s address both the technical challenge and your concerns about unnecessary charges. Together, we’ll stabilize these requests and reduce those frustrating timeouts. 😊


Clarifying the Issue

From your description and logs, it’s clear you’re encountering intermittent connection timeouts with the AmazonResourceExplorer2Client Search API. These timeouts result in repeated retries over 15 minutes, which not only waste time but also increase your billing charges for API calls. Similar issues with S3 and SSM (e.g., PutObjectAsync, SendCommandAsync) suggest a systemic challenge, such as network instability, regional latency, or SDK misconfiguration.

Let’s work through practical solutions to stabilize your connections, reduce retries, and minimize unnecessary costs.


Key Terms

  • Connection Timeout: The maximum time allowed for a client to establish a connection to a server before termination.
  • Retry Logic: Automatic re-execution of failed requests, often with exponential backoff to manage transient issues.
  • Endpoint Configuration: Regional URL used by AWS SDKs to interact with a specific service.
  • HttpClient: The underlying library used by the .NET SDK to handle HTTP requests.

The Solution (Our Recipe)

Steps at a Glance:

  1. Increase the timeout settings for the SDK to allow more time for connections.
  2. Configure custom retry policies to prevent excessive retries and reduce costs.
  3. Use a pre-warmed HTTP connection pool to avoid socket exhaustion.
  4. Diagnose network stability and DNS resolution to ensure reliable connections.
  5. Monitor and analyze costs using AWS Cost Explorer and billing reports.

Step-by-Step Guide:

  1. Increase the Timeout Settings for the SDK
    Longer timeout values ensure connections aren’t prematurely terminated:
    var config = new AmazonResourceExplorer2Config
    {
        Timeout = TimeSpan.FromSeconds(60),  // Default is 30 seconds
        ReadWriteTimeout = TimeSpan.FromSeconds(60),
    };
    var client = new AmazonResourceExplorer2Client(config);

  1. Configure Custom Retry Policies to Prevent Excessive Retries
    Limit the number of retries to reduce both unnecessary API calls and billing costs:
    var clientConfig = new AmazonResourceExplorer2Config
    {
        MaxErrorRetry = 2,  // Default is 4 retries
        Timeout = TimeSpan.FromSeconds(60),
    };
    var client = new AmazonResourceExplorer2Client(clientConfig);
    This adjustment minimizes retry attempts during connection failures.

  1. Use a Pre-Warmed HTTP Connection Pool
    Avoid socket exhaustion and improve performance by reusing HTTP connections:
    var handler = new HttpClientHandler();
    var httpClient = new HttpClient(handler, disposeHandler: false)
    {
        Timeout = TimeSpan.FromSeconds(60)
    };
    
    var config = new AmazonResourceExplorer2Config
    {
        HttpClientFactory = new MyCustomHttpClientFactory(httpClient)
    };
    var client = new AmazonResourceExplorer2Client(config);
    Example HttpClientFactory implementation:
    public class MyCustomHttpClientFactory : IHttpClientFactory
    {
        private readonly HttpClient _httpClient;
    
        public MyCustomHttpClientFactory(HttpClient httpClient)
        {
            _httpClient = httpClient;
        }
    
        public HttpClient CreateHttpClient(IClientConfig clientConfig)
        {
            return _httpClient;
        }
    }

  1. Diagnose Network Stability and DNS Resolution
    • Use tools like ping or traceroute to check the reliability of the endpoint resource-explorer-2.us-east-2.amazonaws.com.
    • AWS’s VPC Reachability Analyzer can help identify and troubleshoot potential connectivity issues.

  1. Monitor and Analyze Costs
    • Use AWS Cost Explorer to track charges for the Resource Explorer API and related services.
    • Enable detailed billing reports to monitor API call usage and identify spikes caused by retries.

Closing Thoughts

Implementing these solutions will significantly reduce retries, stabilize connections, and help minimize unnecessary charges. By combining timeout adjustments, retry controls, and cost monitoring tools, you’ll have more predictable and cost-effective usage of AWS services.

For further guidance, check out these resources:


Farewell

I hope this resolves your issue, Karl! Let me know if you have further questions or need clarification on any of the steps. Best of luck with your project—I’m confident these adjustments will ease your frustrations and keep those costs in check.


Cheers,

Aaron 🚀😊

answered 2 years ago

  • Thanks Aaron, I'm currently testing some of these suggestions. Will let you know if it fixes our issues.

  • Hi Aaron, I updated our code and tested for these conditions - I am still seeing the timeouts. It looks like the changes in the AmazonResourceExplorer2Config for the client do not all take effect. The max number of retries (set in the config to 2) did succeed, but the timeout did not. I am seeing timeouts happening after about 45 seconds (I set the timeout values to 2 mins). The SDK logs still do not tell me anything more other than a timeout actually occurred.

0

Refined Strategies to Resolve AmazonResourceExplorer2Client Timeout Issues

Hi Karl,

Thanks for testing the adjustments and following up with your observations. It’s frustrating when changes to configurations don’t fully address the problem, but your feedback provides valuable insight to refine the solution. Let’s dive into what might be happening and some additional steps to pinpoint and resolve the issue.


Why the Timeout Changes Might Not Apply

The timeout behavior you’re observing suggests that the configuration isn’t being fully propagated or respected by the SDK’s underlying HttpClient. This can happen if:

  1. Custom HttpClient Settings: The SDK might not override certain default HttpClient settings unless explicitly managed.
  2. Service-Specific Constraints: The AWS Resource Explorer service may have inherent timeout limits unrelated to your client-side configuration.
  3. Network or Middleware Interference: Firewalls, proxies, or network configurations could be introducing unexpected delays.

Here’s how you can address these possibilities:


Refined Timeout Management

If the SDK isn’t fully applying your timeout values, you can enforce them explicitly using a custom HttpClient and HttpClientFactory. Ensure all timeout values align:

var httpClientHandler = new HttpClientHandler();
var httpClient = new HttpClient(httpClientHandler)
{
    Timeout = TimeSpan.FromMinutes(2) // Explicitly set here
};

var config = new AmazonResourceExplorer2Config
{
    Timeout = TimeSpan.FromMinutes(2), // SDK-level timeout
    HttpClientFactory = new MyCustomHttpClientFactory(httpClient)
};

var client = new AmazonResourceExplorer2Client(config);

This ensures consistency across the SDK and HttpClient.


Check AWS SDK Behavior

The AWS SDK may have internal timeouts separate from the ones you configure. Verify if the SDK overrides certain settings by enabling more detailed logs:

Amazon.AWSConfigs.LoggingConfig.LogResponses = ResponseLoggingOption.Always;
Amazon.AWSConfigs.LoggingConfig.LogMetrics = true;

These logs can reveal whether the SDK imposes additional restrictions.


Investigate the Service Endpoint

The intermittent nature of timeouts hints at potential service-level or network issues. Here’s how to investigate:

  1. Regional Endpoint Performance: Test an alternate AWS region (e.g., us-east-1) to see if it reduces timeouts. Some regions may experience higher latency during peak hours.
  2. VPC Reachability Analyzer: If running from an EC2 instance, ensure your VPC and subnet configurations aren’t introducing latency.
  3. Local Network Conditions: Use traceroute or similar tools to check for bottlenecks between your application and the AWS endpoint.

Leverage AWS Support for Service-Specific Insights

AWS Support can provide more detailed visibility into timeouts and retries from the service side. They might identify:

  • Throttling issues or rate limits.
  • Specific latencies in your request path.
  • Misconfigurations affecting request handling.

Share your logs and timeout observations with AWS Support to expedite their investigation.


Final Recommendations

  • Test Alternate AWS SDK Versions: The version you’re using (3.7.402.24) may have specific quirks. Testing a newer or slightly older version might yield different results.
  • Short-Term Workaround: If timeouts persist, you could implement a circuit breaker pattern to pause retries after consecutive failures, helping mitigate unnecessary billing and delays.
  • Monitor with AWS CloudWatch: Use detailed CloudWatch metrics to track the latency of API calls and identify trends during intermittent failures.

Closing Thoughts

Karl, I understand how persistent timeouts can disrupt workflows, and I hope these refined steps help you zero in on the root cause. Keep me updated on your progress—your insights can lead to an even more robust solution.


Cheers,
Aaron 🚀😊

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.