From 97e881b955b91b07ac7b6fbc0718f0ecf009dc84 Mon Sep 17 00:00:00 2001 From: Uma Maheswara Rao G Date: Tue, 31 Dec 2013 16:24:02 +0000 Subject: [PATCH] HDFS-5671. Fix socket leak in DFSInputStream#getBlockReader. Contributed by JamesLi git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1554553 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 2 ++ .../apache/hadoop/hdfs/DFSInputStream.java | 20 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 303e64d3d61..55c0a8b612e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -1025,6 +1025,8 @@ Release 2.3.0 - UNRELEASED HDFS-5582. hdfs getconf -excludeFile or -includeFile always failed (sathish via cmccabe) + HDFS-5671. Fix socket leak in DFSInputStream#getBlockReader. (JamesLi via umamahesh) + Release 2.2.0 - 2013-10-13 INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java index 3d26a98b56d..47efcf339a3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java @@ -1188,11 +1188,21 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead, } // Try to create a new remote peer. Peer peer = newTcpPeer(dnAddr); - return BlockReaderFactory.newBlockReader( - dfsClient.getConf(), file, block, blockToken, startOffset, - len, verifyChecksum, clientName, peer, chosenNode, - dsFactory, peerCache, fileInputStreamCache, false, - curCachingStrategy); + try { + reader = BlockReaderFactory.newBlockReader(dfsClient.getConf(), file, + block, blockToken, startOffset, len, verifyChecksum, clientName, + peer, chosenNode, dsFactory, peerCache, fileInputStreamCache, false, + curCachingStrategy); + return reader; + } catch (IOException ex) { + DFSClient.LOG.debug( + "Exception while getting block reader, closing stale " + peer, ex); + throw ex; + } finally { + if (reader == null) { + IOUtils.closeQuietly(peer); + } + } }