Skip to content

Commit c0e294f

Browse files
jnpzhe-thoughts
authored andcommitted
HADOOP-10829. Iteration on CredentialProviderFactory.serviceLoader is thread-unsafe. Contributed by Benoy Antony and Rakesh R.
(cherry picked from commit b82485d)
1 parent 7be52c9 commit c0e294f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/alias/CredentialProviderFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.net.URI;
2323
import java.net.URISyntaxException;
2424
import java.util.ArrayList;
25+
import java.util.Iterator;
2526
import java.util.List;
2627
import java.util.ServiceLoader;
2728

@@ -47,6 +48,15 @@ public abstract CredentialProvider createProvider(URI providerName,
4748
private static final ServiceLoader<CredentialProviderFactory> serviceLoader =
4849
ServiceLoader.load(CredentialProviderFactory.class);
4950

51+
// Iterate through the serviceLoader to avoid lazy loading.
52+
// Lazy loading would require synchronization in concurrent use cases.
53+
static {
54+
Iterator<CredentialProviderFactory> iterServices = serviceLoader.iterator();
55+
while (iterServices.hasNext()) {
56+
iterServices.next();
57+
}
58+
}
59+
5060
public static List<CredentialProvider> getProviders(Configuration conf
5161
) throws IOException {
5262
List<CredentialProvider> result = new ArrayList<CredentialProvider>();

0 commit comments

Comments
 (0)