HDFS-11850. Ozone: Stack Overflow in XceiverClientManager because of race condition in accessing openClient. Contributed by Mukul Kumar Singh.
This commit is contained in:
parent
ae5242accb
commit
a0f51ee3d7
|
@ -105,7 +105,9 @@ public class XceiverClientManager {
|
|||
Preconditions.checkArgument(pipeline.getMachines() != null);
|
||||
Preconditions.checkArgument(!pipeline.getMachines().isEmpty());
|
||||
String containerName = pipeline.getContainerName();
|
||||
XceiverClientWithAccessInfo info = openClient.getIfPresent(containerName);
|
||||
synchronized(openClient) {
|
||||
XceiverClientWithAccessInfo info =
|
||||
openClient.getIfPresent(containerName);
|
||||
|
||||
if (info != null) {
|
||||
// we do have this connection, add reference and return
|
||||
|
@ -113,7 +115,7 @@ public class XceiverClientManager {
|
|||
return info.getXceiverClient();
|
||||
} else {
|
||||
// connection not found, create new, add reference and return
|
||||
final XceiverClientSpi xceiverClient = useRatis?
|
||||
final XceiverClientSpi xceiverClient = useRatis ?
|
||||
XceiverClientRatis.newXceiverClientRatis(pipeline, conf)
|
||||
: new XceiverClient(pipeline, conf);
|
||||
try {
|
||||
|
@ -123,12 +125,11 @@ public class XceiverClientManager {
|
|||
}
|
||||
info = new XceiverClientWithAccessInfo(xceiverClient);
|
||||
info.incrementReference();
|
||||
synchronized (openClient) {
|
||||
openClient.put(containerName, info);
|
||||
}
|
||||
return xceiverClient;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases an XceiverClient after use.
|
||||
|
@ -141,10 +142,10 @@ public class XceiverClientManager {
|
|||
XceiverClientWithAccessInfo info;
|
||||
synchronized (openClient) {
|
||||
info = openClient.getIfPresent(containerName);
|
||||
}
|
||||
Preconditions.checkNotNull(info);
|
||||
info.decrementReference();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper class for caching and cleaning XceiverClient. Three parameters:
|
||||
|
|
Loading…
Reference in New Issue