[ 
https://issues.apache.org/jira/browse/HADOOP-11392?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14243235#comment-14243235
 ] 

Chris Nauroth commented on HADOOP-11392:
----------------------------------------

I don't think there is really a problem.  In the example in the description, 
the fourth argument to {{IOUtils#copyBytes}} is {{true}}.  This tells 
{{IOUtils#copyBytes}} to close the streams automatically.  This happens whether 
the copy is successful or not.

{code}
  /**
   * Copies from one stream to another.
   *
   * @param in InputStrem to read from
   * @param out OutputStream to write to
   * @param buffSize the size of the buffer 
   * @param close whether or not close the InputStream and 
   * OutputStream at the end. The streams are closed in the finally clause.  
   */
  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);
      }
    }
  }
{code}

There is one other point in {{FileUtil}} that passes {{false}} for the fourth 
parameter, but this one takes care of closing streams by itself in {{finally}} 
blocks.

> FileUtil.java leaks file descriptor when copybytes success.
> -----------------------------------------------------------
>
>                 Key: HADOOP-11392
>                 URL: https://issues.apache.org/jira/browse/HADOOP-11392
>             Project: Hadoop Common
>          Issue Type: Bug
>            Reporter: Brahma Reddy Battula
>            Assignee: Brahma Reddy Battula
>         Attachments: HADOOP-11392.patch
>
>
>  Please check following code for same..
> {code}
> try {
>         in = srcFS.open(src);
>         out = dstFS.create(dst, overwrite);
>         IOUtils.copyBytes(in, out, conf, true);
>       } catch (IOException e) {
>         IOUtils.closeStream(out);
>         IOUtils.closeStream(in);
>         throw e;
>       }
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to