Skip to content

Conversation

@shameersss1
Copy link
Contributor

Description of changes:

The exception occurs in the AWS SDK's internal AttributeMap.Builder.resolveValue() method at line 396, which validates that configuration attributes
are not null. The stack trace shows:

java.lang.NullPointerException: Encountered a null value when resolving configuration attributes.
This is commonly caused by concurrent modifications to non-thread-safe types.

The Threading Problem

Original Code Structure:

public class S3AccessGrantsPlugin implements SdkPlugin {
    // Instance field - SHARED across all threads
    ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder()
        .putAdvancedOption(SdkAdvancedClientOption.USER_AGENT_PREFIX, userAgent()).build();
    
    @Override
    public void configureClient(SdkServiceClientConfiguration.Builder config) {
        // Multiple threads use the SAME overrideConfig instance
        s3ControlAsyncClient = s3ControlBuilder.region(destinationRegion)
            .overrideConfiguration(overrideConfig).build();
    }
}

What Happens During Concurrent Access:

  1. Thread A calls configureClient() and accesses overrideConfig
  2. Thread B simultaneously calls configureClient() and accesses the same overrideConfig
  3. Both threads invoke overrideConfiguration(overrideConfig) on their respective builders
  4. The AWS SDK internally processes the ClientOverrideConfiguration using AttributeMap.Builder
  5. AttributeMap.Builder is not thread-safe - its internal state gets corrupted
  6. When resolveValue() is called, it finds null values where valid configuration should exist
  7. The Validate.notNull() check fails, throwing the NullPointerException

Internal AWS SDK Flow

S3ControlAsyncClient.builder()
  └── overrideConfiguration(overrideConfig)
      └── DefaultS3ControlAsyncClientBuilder.buildClient()
          └── SdkDefaultClientBuilder.asyncClientConfiguration()
              └── AttributeMap.Builder.build()
                  └── AttributeMap.Builder.resolveValue() ← NPE occurs here

The AttributeMap Threading Issue

The AttributeMap.Builder maintains internal collections that are modified during configuration resolution:

// Inside AttributeMap.Builder (AWS SDK internal code)
private final Map<AttributeKey<?>, Object> attributes = new HashMap<>();

public AttributeMap build() {
    attributes.forEach((key, value) -> {
        // resolveValue() called for each attribute
        resolveValue(key, value); // ← Concurrent modification causes null values
    });
}

When multiple threads modify this map concurrently, the HashMap's internal structure becomes inconsistent, leading to null values being returned for
valid keys.

@shameersss1 shameersss1 requested a review from a team as a code owner September 3, 2025 10:19
* */
@Override
public void configureClient(SdkServiceClientConfiguration.Builder config) {
ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider moving closer to usage (line 105).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

accessGrantsPlugin.configureClient(config);
successCount.incrementAndGet();
} catch (Exception e) {
exceptionCount.incrementAndGet();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: log exception for easier test failure troubleshooting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

@shameersss1 shameersss1 requested a review from vrozov September 8, 2025 07:24
Copy link

@vrozov vrozov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shiva958
Copy link
Collaborator

shiva958 commented Sep 9, 2025

LGTM! Tests are also passing. Any failures in automation tests are due to dependency graph update problems and will not be related to this PR.

@shiva958 shiva958 merged commit 82852a7 into aws:main Sep 9, 2025
1 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants