HDFS-13039. StripedBlockReader.createBlockReader leaks socket on IOException. (Lei (Eddy) Xu)

This commit is contained in:
Lei Xu 2018-01-19 16:40:58 -08:00
parent c191538ed1
commit 2ed9d61aad
1 changed files with 3 additions and 1 deletions

View File

@ -105,6 +105,7 @@ class StripedBlockReader {
if (offsetInBlock >= block.getNumBytes()) {
return null;
}
Peer peer = null;
try {
InetSocketAddress dnAddr =
stripedReader.getSocketAddress4Transfer(source);
@ -120,7 +121,7 @@ class StripedBlockReader {
*
* TODO: add proper tracer
*/
Peer peer = newConnectedPeer(block, dnAddr, blockToken, source);
peer = newConnectedPeer(block, dnAddr, blockToken, source);
if (peer.isLocal()) {
this.isLocal = true;
}
@ -131,6 +132,7 @@ class StripedBlockReader {
} catch (IOException e) {
LOG.info("Exception while creating remote block reader, datanode {}",
source, e);
IOUtils.closeStream(peer);
return null;
}
}