Description
Describe the bug
This is a follow up to #1996 and is possibly related to #2000
Following an update to the SDK, the initial construction of the client on a network request increased to more than 30 seconds. I've spent some more time on this issue and my findings are below.
Expected Behavior
Client construction should be under 2 seconds.
Current Behavior
Client construction takes more than 30 seconds as you can see in the call tree:
Reproduction Steps
- Create a .NET 6 API with
AWSSDK.Extensions.NETCore.Setup
+AWSSDK.S3
. - Configure an AWS profile and set the configuration in
appsettings.json
- Ensure no Environment variables or other settings cause
DefaultsMode
to be set. - Configure DI:
services.AddDefaultAWSOptions(Configuration.GetAWSOptions());
services.AddAWSService<IAmazonS3>();
- Request
IAmazonS3
in a controller.
Possible Solution
Stepping through the problem, the cause is this check:
aws-sdk-net/extensions/src/AWSSDK.Extensions.NETCore.Setup/ClientFactory.cs
Lines 238 to 240 in c957aa1
When the getter is called on DefaultConfigurationMode
, if it hasn't already been set it and is not available locally, it ends up calling this.DefaultConfiguration
which then results in the call tree above.
Setting "DefaultsMode": "Standard"
in appsettings
resolves the problem.
DefaultsMode
/DefaultConfigurationMode
is not well documented in regards to the .NET SDK and I don't see it in the examples, thus I would consider this unexpected behavior for the majority of consumers.
Additional Information/Context
No response
AWS .NET SDK and/or Package version used
AWSSDK.S3 3.7.9.2
AWSSDK.Extensions.NETCore.Setup 3.7.2
Targeted .NET Platform
.NET 6
Operating System and version
Windows 11