HADOOP-14195. CredentialProviderFactory$getProviders is not thread-safe. Contributed by Vihang Karajgaonkar.
(cherry picked from commit 128015584d
)
This commit is contained in:
parent
47d3c29e30
commit
a92f654aa2
|
@ -54,12 +54,16 @@ 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
|
||||||
CredentialProvider kp = factory.createProvider(uri, conf);
|
// serviceLoader iterator is not thread-safe.
|
||||||
if (kp != null) {
|
synchronized (serviceLoader) {
|
||||||
result.add(kp);
|
for (CredentialProviderFactory factory : serviceLoader) {
|
||||||
found = true;
|
CredentialProvider kp = factory.createProvider(uri, conf);
|
||||||
break;
|
if (kp != null) {
|
||||||
|
result.add(kp);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
|
|
Loading…
Reference in New Issue