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

copyBytes hangs when the configuration file is corrupted

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Patch Available
    • Minor
    • Resolution: Unresolved
    • 0.23.0, 2.5.0, 3.1.0
    • None
    • common
    • None

    Description

      The third parameter,  buffSize, is read from the configuration files or user-specified.

      When the configuration file is corrupted or the user configures with a wrong value, i.e., 0, the bytesRead will always be 0, making the while loop's condition always true, hanging IOUtils.copyBytes() endlessly.

      Here is the snippet of the code. There are four copyBytes in the following code. The 3rd and 4th copyBytes calls the 1st one. The 1st one calls the 2nd one. Hang happens in the while loop of the second copyBytes function.

       

      //1st copyBytes
        public static void copyBytes(InputStream in, OutputStream out, int buffSize, boolean close) 
          throws IOException {
          try {
            copyBytes(in, out, buffSize);
            if(close) {
              out.close();
              out = null;
              in.close();
              in = null;
            }
          } finally {
            if(close) {
              closeStream(out);
              closeStream(in);
            }
          }
        }
        
      //2nd copyBytes
        public static void copyBytes(InputStream in, OutputStream out, int buffSize) 
          throws IOException {
          PrintStream ps = out instanceof PrintStream ? (PrintStream)out : null;
          byte buf[] = new byte[buffSize];
          int bytesRead = in.read(buf);
          while (bytesRead >= 0) {
            out.write(buf, 0, bytesRead);
            if ((ps != null) && ps.checkError()) {
              throw new IOException("Unable to write to output stream.");
            }
            bytesRead = in.read(buf);
          }
        }
      
      //3rd copyBytes
        public static void copyBytes(InputStream in, OutputStream out, Configuration conf)
          throws IOException {
          copyBytes(in, out, conf.getInt("io.file.buffer.size", 4096), true);
        }
        
      //4th copyBytes
        public static void copyBytes(InputStream in, OutputStream out, Configuration conf, boolean close)
          throws IOException {
          copyBytes(in, out, conf.getInt("io.file.buffer.size", 4096),  close);
        }
      

       

      Attachments

        1. HADOOP-15415.001.patch
          2 kB
          Yiqun Lin

        Activity

          People

            linyiqun Yiqun Lin
            dustinday John Doe
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: