Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I’m running an AWS Lambda written in Java 21 with Spring Boot 3. My Lambda uses an S3 client, which I instantiate as follows:

@Configuration
public class AwsConfig {
    @Bean
    public S3Client awsS3Client() {
        return S3Client.builder()
                .region(Region.of("us-west-1"))
                .build();
    }
}

Problem:
When I invoke the Lambda multiple times in sequence, the AWS environment appears to create a new S3Client before the previous one is garbage collected. This leads to the following error:

No duplicate IdentityProperty names allowed but both IdentityProperties 7890fbf9 and 25f0f461 have the same namespace (java.lang.String) and name (Bucket). IdentityProperty should be referenced from a shared static constant to protect against erroneous or unexpected collisions.

If I wait 5 to 7 minutes before rerunning the lambda, everything works perfectly fine, but it's obviously not acceptable.

From debugging, I see this comes from the AWS SDK’s IdentityProperty class, specifically:

private static final ConcurrentMap<Pair<String, String>, IdentityProperty<?>> NAME_HISTORY = new ConcurrentHashMap<>();

private void ensureUnique() {
    IdentityProperty<?> prev = NAME_HISTORY.putIfAbsent(Pair.of(namespace, name), this);
    Validate.isTrue(prev == null,
        "No duplicate IdentityProperty names allowed but both IdentityProperties %s and %s have the same "
        + "namespace (%s) and name (%s). IdentityProperty should be referenced from a shared static constant to "
        + "protect against erroneous or unexpected collisions.",
        Integer.toHexString(System.identityHashCode(prev)),
        Integer.toHexString(System.identityHashCode(this)),
        namespace,
        name);
}

It seems that after the first Lambda invocation, NAME_HISTORY is not cleared, so subsequent invocations fail when trying to register the same "java.lang.String"/"Bucket" key.

This method is called by S3ExpressAuthSchemeProvider, which is in turn called by DefaultS3ClientBuilder.

What I’ve tried:

  • Declaring the S3Client as a static class variable
  • Using @Scope("prototype") for the bean
  • (As a hack) Removing the property from the NAME_HISTORY map via reflection (which just led to a similar error for another property)
  • Various other bean lifecycle and instantiation strategies

Question:

  • How can I prevent this error?
You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.