HADOOP-14195. CredentialProviderFactory$getProviders is not thread-safe. Contributed by Vihang Karajgaonkar.
(cherry picked from commit128015584d
) (cherry picked from commita92f654aa2
)
This commit is contained in:
parent
7a3f9e8fac
commit
fac5bdc023
|
@ -54,12 +54,16 @@ public abstract class CredentialProviderFactory {
|
|||
try {
|
||||
URI uri = new URI(path);
|
||||
boolean found = false;
|
||||
for(CredentialProviderFactory factory: serviceLoader) {
|
||||
CredentialProvider kp = factory.createProvider(uri, conf);
|
||||
if (kp != null) {
|
||||
result.add(kp);
|
||||
found = true;
|
||||
break;
|
||||
// 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) {
|
||||
result.add(kp);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
|
|
Loading…
Reference in New Issue