Skip to content

Commit 8e55ccc

Browse files
authored
Fixed bug where using profile-based credentials could cause the SDK to read the profile file with each request. (#3950)
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 ```
1 parent 34d0270 commit 8e55ccc

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "AWS SDK for Java v2",
3+
"contributor": "",
4+
"type": "bugfix",
5+
"description": "Fixed bug where using profile-based credentials could cause the SDK to read the profile file with each request."
6+
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/client/builder/SdkDefaultClientBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ protected SdkClientConfiguration mergeChildDefaults(SdkClientConfiguration confi
264264
*/
265265
private SdkClientConfiguration mergeGlobalDefaults(SdkClientConfiguration configuration) {
266266
// Don't load the default profile file if the customer already gave us one.
267-
Supplier<ProfileFile> configuredProfileFileSupplier = configuration.option(PROFILE_FILE_SUPPLIER);
268-
Supplier<ProfileFile> profileFileSupplier = Optional.ofNullable(configuredProfileFileSupplier)
269-
.orElseGet(() -> ProfileFile::defaultProfileFile);
267+
Supplier<ProfileFile> profileFileSupplier =
268+
Optional.ofNullable(configuration.option(PROFILE_FILE_SUPPLIER))
269+
.orElseGet(() -> ProfileFileSupplier.fixedProfileFile(ProfileFile.defaultProfileFile()));
270270

271271
return configuration.merge(c -> c.option(EXECUTION_INTERCEPTORS, new ArrayList<>())
272272
.option(ADDITIONAL_HTTP_HEADERS, new LinkedHashMap<>())

core/sdk-core/src/test/java/software/amazon/awssdk/core/client/builder/DefaultClientBuilderTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import java.util.List;
5353
import java.util.Map;
5454
import java.util.Optional;
55+
import java.util.function.Supplier;
5556
import org.assertj.core.api.Assertions;
5657
import org.junit.Before;
5758
import org.junit.Test;
@@ -371,7 +372,19 @@ public void clientBuilderFieldsHaveBeanEquivalents() throws Exception {
371372
assertThat(property.getWriteMethod()).as(propertyName + " setter").isNotNull();
372373
});
373374
});
375+
}
376+
377+
378+
@Test
379+
public void defaultProfileFileSupplier_isStaticOrHasIdentityCaching() {
380+
SdkClientConfiguration config =
381+
testClientBuilder().build().clientConfiguration;
382+
383+
Supplier<ProfileFile> defaultProfileFileSupplier = config.option(PROFILE_FILE_SUPPLIER);
384+
ProfileFile firstGet = defaultProfileFileSupplier.get();
385+
ProfileFile secondGet = defaultProfileFileSupplier.get();
374386

387+
assertThat(secondGet).isSameAs(firstGet);
375388
}
376389

377390
private SdkDefaultClientBuilder<TestClientBuilder, TestClient> testClientBuilder() {

0 commit comments

Comments
 (0)