HADOOP-14195. CredentialProviderFactory$getProviders is not thread-safe. Contributed by Vihang Karajgaonkar.

This commit is contained in:
John Zhuge 2017-03-23 13:56:19 -07:00
parent d35e79abc2
commit 128015584d
1 changed files with 10 additions and 6 deletions

View File

@ -56,7 +56,10 @@ public abstract class CredentialProviderFactory {
try { try {
URI uri = new URI(path); URI uri = new URI(path);
boolean found = false; boolean found = false;
for(CredentialProviderFactory factory: serviceLoader) { // Iterate serviceLoader in a synchronized block since
// serviceLoader iterator is not thread-safe.
synchronized (serviceLoader) {
for (CredentialProviderFactory factory : serviceLoader) {
CredentialProvider kp = factory.createProvider(uri, conf); CredentialProvider kp = factory.createProvider(uri, conf);
if (kp != null) { if (kp != null) {
result.add(kp); result.add(kp);
@ -64,6 +67,7 @@ public abstract class CredentialProviderFactory {
break; break;
} }
} }
}
if (!found) { if (!found) {
throw new IOException("No CredentialProviderFactory for " + uri + " in " + throw new IOException("No CredentialProviderFactory for " + uri + " in " +
CREDENTIAL_PROVIDER_PATH); CREDENTIAL_PROVIDER_PATH);