Skip to content

Failure to set DefaultConfigurationMode causes performance issues during client construction #2022

Closed
@Hawxy

Description

@Hawxy

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:

image

Reproduction Steps

  1. Create a .NET 6 API with AWSSDK.Extensions.NETCore.Setup + AWSSDK.S3.
  2. Configure an AWS profile and set the configuration in appsettings.json
  3. Ensure no Environment variables or other settings cause DefaultsMode to be set.
  4. Configure DI:
 services.AddDefaultAWSOptions(Configuration.GetAWSOptions());
 services.AddAWSService<IAmazonS3>();
  1. Request IAmazonS3 in a controller.

Possible Solution

Stepping through the problem, the cause is this check:

if (string.Equals(property.Name, "RetryMode", StringComparison.Ordinal) &&
defaultConfig.RetryMode == RequestRetryMode.Legacy &&
config.DefaultConfigurationMode != DefaultConfigurationMode.Legacy)

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions