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

(cherry picked from commit 128015584d)
(cherry picked from commit a92f654aa2)
This commit is contained in:
John Zhuge 2017-04-12 20:02:39 -07:00
parent 7a3f9e8fac
commit fac5bdc023
1 changed files with 10 additions and 6 deletions

View File

@ -54,6 +54,9 @@ public abstract class CredentialProviderFactory {
try {
URI uri = new URI(path);
boolean found = false;
// 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);
if (kp != null) {
@ -62,6 +65,7 @@ public abstract class CredentialProviderFactory {
break;
}
}
}
if (!found) {
throw new IOException("No CredentialProviderFactory for " + uri + " in " +
CREDENTIAL_PROVIDER_PATH);