From 8d4f236665f1a9f038a95eacfa5cb25e9cd41931 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Tue, 25 Apr 2023 17:55:49 +0000 Subject: [PATCH] Fixed bug where using profile-based credentials could cause the SDK to read the profile file with each request. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This bug was introduced with the profile file supplier changes. If the customer was not overriding the profile file via the client override config AND was relying on profile file-based configuration, that configuration would be read with every request. This had a significant performance cost. ``` Benchmarking Results (software.amazon.awssdk.benchmark.apicall.protocol.JsonProtocolBenchmark) Before: 2858.805 ± 181.491 ops/s After: 10915.079 ± 677.022 ops/s ``` --- .../bugfix-AWSSDKforJavav2-c9734ed.json | 6 ++++++ .../client/builder/SdkDefaultClientBuilder.java | 6 +++--- .../client/builder/DefaultClientBuilderTest.java | 13 +++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 .changes/next-release/bugfix-AWSSDKforJavav2-c9734ed.json diff --git a/.changes/next-release/bugfix-AWSSDKforJavav2-c9734ed.json b/.changes/next-release/bugfix-AWSSDKforJavav2-c9734ed.json new file mode 100644 index 000000000000..9a73e253204a --- /dev/null +++ b/.changes/next-release/bugfix-AWSSDKforJavav2-c9734ed.json @@ -0,0 +1,6 @@ +{ + "category": "AWS SDK for Java v2", + "contributor": "", + "type": "bugfix", + "description": "Fixed bug where using profile-based credentials could cause the SDK to read the profile file with each request." +} diff --git a/core/sdk-core/src/main/java/software/amazon/awssdk/core/client/builder/SdkDefaultClientBuilder.java b/core/sdk-core/src/main/java/software/amazon/awssdk/core/client/builder/SdkDefaultClientBuilder.java index 67f8295ee49c..c91ad39ad1a3 100644 --- a/core/sdk-core/src/main/java/software/amazon/awssdk/core/client/builder/SdkDefaultClientBuilder.java +++ b/core/sdk-core/src/main/java/software/amazon/awssdk/core/client/builder/SdkDefaultClientBuilder.java @@ -264,9 +264,9 @@ protected SdkClientConfiguration mergeChildDefaults(SdkClientConfiguration confi */ private SdkClientConfiguration mergeGlobalDefaults(SdkClientConfiguration configuration) { // Don't load the default profile file if the customer already gave us one. - Supplier configuredProfileFileSupplier = configuration.option(PROFILE_FILE_SUPPLIER); - Supplier profileFileSupplier = Optional.ofNullable(configuredProfileFileSupplier) - .orElseGet(() -> ProfileFile::defaultProfileFile); + Supplier profileFileSupplier = + Optional.ofNullable(configuration.option(PROFILE_FILE_SUPPLIER)) + .orElseGet(() -> ProfileFileSupplier.fixedProfileFile(ProfileFile.defaultProfileFile())); return configuration.merge(c -> c.option(EXECUTION_INTERCEPTORS, new ArrayList<>()) .option(ADDITIONAL_HTTP_HEADERS, new LinkedHashMap<>()) diff --git a/core/sdk-core/src/test/java/software/amazon/awssdk/core/client/builder/DefaultClientBuilderTest.java b/core/sdk-core/src/test/java/software/amazon/awssdk/core/client/builder/DefaultClientBuilderTest.java index 8bb2455099ba..ec526330cdc9 100644 --- a/core/sdk-core/src/test/java/software/amazon/awssdk/core/client/builder/DefaultClientBuilderTest.java +++ b/core/sdk-core/src/test/java/software/amazon/awssdk/core/client/builder/DefaultClientBuilderTest.java @@ -52,6 +52,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.function.Supplier; import org.assertj.core.api.Assertions; import org.junit.Before; import org.junit.Test; @@ -371,7 +372,19 @@ public void clientBuilderFieldsHaveBeanEquivalents() throws Exception { assertThat(property.getWriteMethod()).as(propertyName + " setter").isNotNull(); }); }); + } + + + @Test + public void defaultProfileFileSupplier_isStaticOrHasIdentityCaching() { + SdkClientConfiguration config = + testClientBuilder().build().clientConfiguration; + + Supplier defaultProfileFileSupplier = config.option(PROFILE_FILE_SUPPLIER); + ProfileFile firstGet = defaultProfileFileSupplier.get(); + ProfileFile secondGet = defaultProfileFileSupplier.get(); + assertThat(secondGet).isSameAs(firstGet); } private SdkDefaultClientBuilder testClientBuilder() {