Skip to content

Commit b82485d

Browse files
committed
HADOOP-10829. Iteration on CredentialProviderFactory.serviceLoader is thread-unsafe. Contributed by Benoy Antony and Rakesh R.
1 parent d94b30c commit b82485d

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

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

@@ -49,6 +50,15 @@ public abstract CredentialProvider createProvider(URI providerName,
4950
ServiceLoader.load(CredentialProviderFactory.class,
5051
CredentialProviderFactory.class.getClassLoader());
5152

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

0 commit comments

Comments
 (0)