question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

STS not on class path when using parallel stream

See original GitHub issue

Running EcrClient.listImagesPaginator() in a Collection.parallelStream() using Spring Boot sometimes results in WebIdentityCredentialsUtils.factory() not finding STS on its class path.

Describe the issue

Sometimes when I execute the above I get the error message: “To use web identity tokens, the ‘sts’ service module must be on the class path.”. I know that parallel streams delegates work to the ForkJoin common pool, and it seems that sometimes some threads from this pool might have a class loader that does not have STS on its path. (Maybe because of Spring? I noticed that the loader called “app” does not have STS)

Is there a reason you guys are using Thread.currentThread().getContextClassLoader(), instead of Object.getClass().getClassLoader() in the WebIdentityCredentialsUtils class?

I admit I know little about class loaders and how you use them, but I cannot use parallelStream() reliably at the moment. Or do you advise against using parallelStream at all?

Not filing as bug, since it might be intended behaviour.

Steps to Reproduce

I am listing docker images from multiple repositories in parallel.

@Override
public Stream<String> listImages(List<String> repositories) {
    return repositories.parallelStream()
        .flatMap(repoName -> ecr.listImagesPaginator(builder -> builder.registryId(this.registryId).repositoryName(repoName).filter(f -> f.tagStatus(TagStatus.TAGGED)))
            .imageIds()
            .stream()
            .map(ImageIdentifier::imageTag));
}

Current Behavior

I get the message “To use web identity tokens, the ‘sts’ service module must be on the class path.” instead of it finding STS and using the token credentials.

Your Environment

  • AWS Java SDK version used: 2.14.18
  • JDK version used: 13
  • Operating System and version: Using the openjdk:13 image, which uses Oracle Linux 7 I believe.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
joviegascommented, Nov 6, 2020

Hi @BartXZX Could you please help me to confirm ones, if you have added “sts” module in dependency like

        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>sts</artifactId>
            <version>2.15.20</version>
        </dependency>

or it would be of great help if you could provide all dependencies related to <groupId>software.amazon.awssdk</groupId>

1reaction
BartXZXcommented, Nov 11, 2020

Nevermind, I see it’s already in 25 😃 And I’m happy to say I no longer see the issue!

Of course, it was an issue we saw ‘sometimes’ but usually we had a 50/50 chance to see it on startup. I’ve tested many times now and have not seen it since, so I’m happy. Will let you guys know if I see it pop up again.

Thank you for the quick response!

Read more comments on GitHub >

github_iconTop Results From Across the Web

parallelStream() causing ClassNotFoundException with JAXB ...
We saw that JAXB uses Thread.currentThread().getContextClassLoader() for loading classes. We also saw, that when using parallelStream() , the ...
Read more >
When to Use a Parallel Stream in Java - Baeldung
In this tutorial, we'll explore the differences between sequential and parallel streams using Stream Api.
Read more >
Take Caution Using Java Parallel Streams - JRebel
Today we will look at parallel streams and how using them unwisely ... Every lambda execution is not instantaneous and during all that...
Read more >
The 6 biggest problems of Java 8 - devmio
The 6 biggest problems of Java 8 · 1. Parallel Streams can actually slow you down · 2. The flip-side of Lambda expressions...
Read more >
How to set Permanent Class Path in Eclipse IDE for JDBC ...
The above video explains about how to set permanent class path in Java for jdbc, servlets programs, for connecting Java application and data ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found