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

[AWSSDK.Extensions.NETCore.Setup] ClientFactory incorrectly triggers RegionEndpoint fallback location mechanism which is very slow #3588

Open
1 task
davidkvc opened this issue Dec 23, 2024 · 1 comment
Labels
bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made. module/tools p2 This is a standard priority issue

Comments

@davidkvc
Copy link

Describe the bug

When I'm using this library on dev machine and the library tries to access EC2 metadata on every restart of the app that's very slow and annoying.

After some digging I have found that the problem is in ClientFactory.CreateConfig(...). Specifically, this code tries to avoid the issue above:

// Skip RegionEndpoint because it is set below and calling the get method on the
// property triggers the default region fallback mechanism.
   if (string.Equals(property.Name, "RegionEndpoint", StringComparison.Ordinal))
      continue;

But a few lines below there is check related to RetryMode which accesses config.DefaultConfigurationMode when defaultConfig.RetryMode is Legacy (the default). The access of DefaultConfigurationMode triggers the access of RegionEndpoint internally, which this code tries to avoid in the first place.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

The initialization of service client is fast on dev machine

Current Behavior

The initialization of service client is slow on dev machine because it is trying to incorrectly access EC2 metadata

Reproduction Steps

appsettings.json

{
  "AWS": {
    "Region": "us-east-2",
    "Profile": "my-profile"
  }
}

Asp.Net core app initialized from default template:

builder.Services.AddDefaultAWSOptions(builder.Configuration.GetAWSOptions());
builder.Services.AddAWSService<IAmazonCloudFormation>();

app.Services.GetRequiredService<IAmazonCloudFormation>(); // <- this shouldn't take several seconds

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

AWSSDK.Extensions.NETCore.Setup 3.7.301
AWSSDK.CloudFormation 3.7.401.12

Targeted .NET Platform

.NET 9

Operating System and version

Windows 10

@davidkvc davidkvc added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 23, 2024
@dscpinheiro
Copy link
Contributor

This has been fixed in V4, see this comment for more details: #2022 (comment)

As Norm mentioned there, V3 relies on a lot of reflection so this isn't something we can easily back-port. For a workaround locally, you can add "DefaultsMode": "Standard" to your appsettings file.

@dscpinheiro dscpinheiro added closing-soon This issue will automatically close in 4 days unless further comments are made. and removed needs-triage This issue or PR still needs to be triaged. labels Dec 23, 2024
@ashishdhingra ashishdhingra added module/tools p2 This is a standard priority issue labels Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made. module/tools p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

3 participants