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