Uploaded image for project: 'Hadoop Common'
  1. Hadoop Common
  2. HADOOP-10081

Client.setupIOStreams can leak socket resources on exception or error

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 0.23.9, 2.2.0
    • 0.23.11, 2.3.0
    • ipc
    • None

    Description

      The setupIOStreams method in org.apache.hadoop.ipc.Client can leak socket resources if an exception is thrown before the inStream and outStream local variables are assigned to this.in and this.out, respectively.

      Attachments

        1. HADOOP-10081.1.patch
          0.6 kB
          Tsuyoshi Ozawa

        Activity

          The close method closes this.in and this.out but does not close this.socket which might have helped in these scenarios. One mechanism that can trigger this having a client trying to connect to HDFS on the wrong port (e.g.: web port instead of RPC port). Doing so makes the SASL setup blow up with an OOM error since it's not checking for sane boundaries on string lengths and trying to allocate gigantic byte arrays. Sample backtrace snippet from a 0.23 client:

          Caused by: java.io.IOException: Couldn't set up IO streams
                  at org.apache.hadoop.ipc.Client$Connection.setupIOstreams(Client.java:623)
                  at org.apache.hadoop.ipc.Client$Connection.access$2100(Client.java:207)
                  at org.apache.hadoop.ipc.Client.getConnection(Client.java:1204)
                  at org.apache.hadoop.ipc.Client.call(Client.java:1074)
                  ... 25 more
          Caused by: java.lang.OutOfMemoryError
                  at sun.misc.Unsafe.allocateMemory(Native Method)
                  at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:127)
                  at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:306)
                  at sun.nio.ch.Util.getTemporaryDirectBuffer(Util.java:174)
                  at sun.nio.ch.IOUtil.read(IOUtil.java:196)
                  at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:359)
                  at org.apache.hadoop.net.SocketInputStream$Reader.performIO(SocketInputStream.java:54)
                  at org.apache.hadoop.net.SocketIOWithTimeout.doIO(SocketIOWithTimeout.java:142)
                  at org.apache.hadoop.net.SocketInputStream.read(SocketInputStream.java:154)
                  at org.apache.hadoop.net.SocketInputStream.read(SocketInputStream.java:127)
                  at java.io.FilterInputStream.read(FilterInputStream.java:133)
                  at java.io.BufferedInputStream.read1(BufferedInputStream.java:273)
                  at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
                  at java.io.DataInputStream.readFully(DataInputStream.java:195)
                  at java.io.DataInputStream.readFully(DataInputStream.java:169)
                  at org.apache.hadoop.io.WritableUtils.readString(WritableUtils.java:125)
                  at org.apache.hadoop.security.SaslRpcClient.readStatus(SaslRpcClient.java:114)
                  at org.apache.hadoop.security.SaslRpcClient.saslConnect(SaslRpcClient.java:150)
                  at org.apache.hadoop.ipc.Client$Connection.setupSaslConnection(Client.java:409)
                  at org.apache.hadoop.ipc.Client$Connection.access$1300(Client.java:207)
                  at org.apache.hadoop.ipc.Client$Connection$2.run(Client.java:578)
                  at org.apache.hadoop.ipc.Client$Connection$2.run(Client.java:575)
                  at java.security.AccessController.doPrivileged(Native Method)
          

          There's probably a separate JIRA here for the fact that the SASL layer isn't doing sanity checks on the lengths of strings it's trying to read.

          jlowe Jason Darrell Lowe added a comment - The close method closes this.in and this.out but does not close this.socket which might have helped in these scenarios. One mechanism that can trigger this having a client trying to connect to HDFS on the wrong port (e.g.: web port instead of RPC port). Doing so makes the SASL setup blow up with an OOM error since it's not checking for sane boundaries on string lengths and trying to allocate gigantic byte arrays. Sample backtrace snippet from a 0.23 client: Caused by: java.io.IOException: Couldn't set up IO streams at org.apache.hadoop.ipc.Client$Connection.setupIOstreams(Client.java:623) at org.apache.hadoop.ipc.Client$Connection.access$2100(Client.java:207) at org.apache.hadoop.ipc.Client.getConnection(Client.java:1204) at org.apache.hadoop.ipc.Client.call(Client.java:1074) ... 25 more Caused by: java.lang.OutOfMemoryError at sun.misc.Unsafe.allocateMemory(Native Method) at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:127) at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:306) at sun.nio.ch.Util.getTemporaryDirectBuffer(Util.java:174) at sun.nio.ch.IOUtil.read(IOUtil.java:196) at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:359) at org.apache.hadoop.net.SocketInputStream$Reader.performIO(SocketInputStream.java:54) at org.apache.hadoop.net.SocketIOWithTimeout.doIO(SocketIOWithTimeout.java:142) at org.apache.hadoop.net.SocketInputStream.read(SocketInputStream.java:154) at org.apache.hadoop.net.SocketInputStream.read(SocketInputStream.java:127) at java.io.FilterInputStream.read(FilterInputStream.java:133) at java.io.BufferedInputStream.read1(BufferedInputStream.java:273) at java.io.BufferedInputStream.read(BufferedInputStream.java:334) at java.io.DataInputStream.readFully(DataInputStream.java:195) at java.io.DataInputStream.readFully(DataInputStream.java:169) at org.apache.hadoop.io.WritableUtils.readString(WritableUtils.java:125) at org.apache.hadoop.security.SaslRpcClient.readStatus(SaslRpcClient.java:114) at org.apache.hadoop.security.SaslRpcClient.saslConnect(SaslRpcClient.java:150) at org.apache.hadoop.ipc.Client$Connection.setupSaslConnection(Client.java:409) at org.apache.hadoop.ipc.Client$Connection.access$1300(Client.java:207) at org.apache.hadoop.ipc.Client$Connection$2.run(Client.java:578) at org.apache.hadoop.ipc.Client$Connection$2.run(Client.java:575) at java.security.AccessController.doPrivileged(Native Method) There's probably a separate JIRA here for the fact that the SASL layer isn't doing sanity checks on the lengths of strings it's trying to read.
          ozawa Tsuyoshi Ozawa added a comment -

          Fixed to call closeConnection() method in close() method.

          ozawa Tsuyoshi Ozawa added a comment - Fixed to call closeConnection() method in close() method.
          vinayakumarb Vinayakumar B added a comment -

          +1 Patch looks good for me.

          vinayakumarb Vinayakumar B added a comment - +1 Patch looks good for me.
          hadoopqa Hadoop QA added a comment -

          -1 overall. Here are the results of testing the latest attachment
          http://issues.apache.org/jira/secure/attachment/12613337/HADOOP-10081.1.patch
          against trunk revision .

          +1 @author. The patch does not contain any @author tags.

          -1 tests included. The patch doesn't appear to include any new or modified tests.
          Please justify why no new tests are needed for this patch.
          Also please list what manual steps were performed to verify this patch.

          +1 javac. The applied patch does not increase the total number of javac compiler warnings.

          +1 javadoc. The javadoc tool did not generate any warning messages.

          +1 eclipse:eclipse. The patch built with eclipse:eclipse.

          +1 findbugs. The patch does not introduce any new Findbugs (version 1.3.9) warnings.

          +1 release audit. The applied patch does not increase the total number of release audit warnings.

          +1 core tests. The patch passed unit tests in hadoop-common-project/hadoop-common.

          +1 contrib tests. The patch passed contrib unit tests.

          Test results: https://builds.apache.org/job/PreCommit-HADOOP-Build/3278//testReport/
          Console output: https://builds.apache.org/job/PreCommit-HADOOP-Build/3278//console

          This message is automatically generated.

          hadoopqa Hadoop QA added a comment - -1 overall . Here are the results of testing the latest attachment http://issues.apache.org/jira/secure/attachment/12613337/HADOOP-10081.1.patch against trunk revision . +1 @author . The patch does not contain any @author tags. -1 tests included . The patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch. +1 javac . The applied patch does not increase the total number of javac compiler warnings. +1 javadoc . The javadoc tool did not generate any warning messages. +1 eclipse:eclipse . The patch built with eclipse:eclipse. +1 findbugs . The patch does not introduce any new Findbugs (version 1.3.9) warnings. +1 release audit . The applied patch does not increase the total number of release audit warnings. +1 core tests . The patch passed unit tests in hadoop-common-project/hadoop-common. +1 contrib tests . The patch passed contrib unit tests. Test results: https://builds.apache.org/job/PreCommit-HADOOP-Build/3278//testReport/ Console output: https://builds.apache.org/job/PreCommit-HADOOP-Build/3278//console This message is automatically generated.
          ozawa Tsuyoshi Ozawa added a comment -

          Thank you for review, Vinay.

          ozawa Tsuyoshi Ozawa added a comment - Thank you for review, Vinay.
          ozawa Tsuyoshi Ozawa added a comment -

          I confirmed a latest patch can be applied to the trunk code. Any comments about this JIRA?

          ozawa Tsuyoshi Ozawa added a comment - I confirmed a latest patch can be applied to the trunk code. Any comments about this JIRA?

          Sorry for the delay. +1, lgtm. Committing this shortly.

          jlowe Jason Darrell Lowe added a comment - Sorry for the delay. +1, lgtm. Committing this shortly.
          hudson Hudson added a comment -

          SUCCESS: Integrated in Hadoop-trunk-Commit #4836 (See https://builds.apache.org/job/Hadoop-trunk-Commit/4836/)
          HADOOP-10081. Client.setupIOStreams can leak socket resources on exception or error. Contributed by Tsuyoshi OZAWA (jlowe: http://svn.apache.org/viewcvs.cgi/?root=Apache-SVN&view=rev&rev=1548179)

          • /hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
          • /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java
          hudson Hudson added a comment - SUCCESS: Integrated in Hadoop-trunk-Commit #4836 (See https://builds.apache.org/job/Hadoop-trunk-Commit/4836/ ) HADOOP-10081 . Client.setupIOStreams can leak socket resources on exception or error. Contributed by Tsuyoshi OZAWA (jlowe: http://svn.apache.org/viewcvs.cgi/?root=Apache-SVN&view=rev&rev=1548179 ) /hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java

          Thanks, Tsuyoshi! And thanks to Vinay for helping with the reviews. I committed this to trunk, branch-2, branch-2.3, and branch-0.23.

          jlowe Jason Darrell Lowe added a comment - Thanks, Tsuyoshi! And thanks to Vinay for helping with the reviews. I committed this to trunk, branch-2, branch-2.3, and branch-0.23.
          ozawa Tsuyoshi Ozawa added a comment -

          Thank you, Jason!

          ozawa Tsuyoshi Ozawa added a comment - Thank you, Jason!
          hudson Hudson added a comment -

          FAILURE: Integrated in Hadoop-Yarn-trunk #413 (See https://builds.apache.org/job/Hadoop-Yarn-trunk/413/)
          HADOOP-10081. Client.setupIOStreams can leak socket resources on exception or error. Contributed by Tsuyoshi OZAWA (jlowe: http://svn.apache.org/viewcvs.cgi/?root=Apache-SVN&view=rev&rev=1548179)

          • /hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
          • /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java
          hudson Hudson added a comment - FAILURE: Integrated in Hadoop-Yarn-trunk #413 (See https://builds.apache.org/job/Hadoop-Yarn-trunk/413/ ) HADOOP-10081 . Client.setupIOStreams can leak socket resources on exception or error. Contributed by Tsuyoshi OZAWA (jlowe: http://svn.apache.org/viewcvs.cgi/?root=Apache-SVN&view=rev&rev=1548179 ) /hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java
          hudson Hudson added a comment -

          FAILURE: Integrated in Hadoop-Hdfs-0.23-Build #812 (See https://builds.apache.org/job/Hadoop-Hdfs-0.23-Build/812/)
          svn merge -c 1548179 FIXES: HADOOP-10081. Client.setupIOStreams can leak socket resources on exception or error. Contributed by Tsuyoshi OZAWA (jlowe: http://svn.apache.org/viewcvs.cgi/?root=Apache-SVN&view=rev&rev=1548190)

          • /hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt
          • /hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java
          hudson Hudson added a comment - FAILURE: Integrated in Hadoop-Hdfs-0.23-Build #812 (See https://builds.apache.org/job/Hadoop-Hdfs-0.23-Build/812/ ) svn merge -c 1548179 FIXES: HADOOP-10081 . Client.setupIOStreams can leak socket resources on exception or error. Contributed by Tsuyoshi OZAWA (jlowe: http://svn.apache.org/viewcvs.cgi/?root=Apache-SVN&view=rev&rev=1548190 ) /hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt /hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java
          hudson Hudson added a comment -

          FAILURE: Integrated in Hadoop-Mapreduce-trunk #1630 (See https://builds.apache.org/job/Hadoop-Mapreduce-trunk/1630/)
          HADOOP-10081. Client.setupIOStreams can leak socket resources on exception or error. Contributed by Tsuyoshi OZAWA (jlowe: http://svn.apache.org/viewcvs.cgi/?root=Apache-SVN&view=rev&rev=1548179)

          • /hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
          • /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java
          hudson Hudson added a comment - FAILURE: Integrated in Hadoop-Mapreduce-trunk #1630 (See https://builds.apache.org/job/Hadoop-Mapreduce-trunk/1630/ ) HADOOP-10081 . Client.setupIOStreams can leak socket resources on exception or error. Contributed by Tsuyoshi OZAWA (jlowe: http://svn.apache.org/viewcvs.cgi/?root=Apache-SVN&view=rev&rev=1548179 ) /hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java
          hudson Hudson added a comment -

          SUCCESS: Integrated in Hadoop-Hdfs-trunk #1604 (See https://builds.apache.org/job/Hadoop-Hdfs-trunk/1604/)
          HADOOP-10081. Client.setupIOStreams can leak socket resources on exception or error. Contributed by Tsuyoshi OZAWA (jlowe: http://svn.apache.org/viewcvs.cgi/?root=Apache-SVN&view=rev&rev=1548179)

          • /hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
          • /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java
          hudson Hudson added a comment - SUCCESS: Integrated in Hadoop-Hdfs-trunk #1604 (See https://builds.apache.org/job/Hadoop-Hdfs-trunk/1604/ ) HADOOP-10081 . Client.setupIOStreams can leak socket resources on exception or error. Contributed by Tsuyoshi OZAWA (jlowe: http://svn.apache.org/viewcvs.cgi/?root=Apache-SVN&view=rev&rev=1548179 ) /hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java

          People

            ozawa Tsuyoshi Ozawa
            jlowe Jason Darrell Lowe
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: