Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-681

InputStream obtained from HttpMethod.getResponseBodyAsStream() could not be closed before the end of the stream

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Invalid
    • 3.0.1
    • None
    • None
    • None
    • FreeBSD-6.2-STABLE, diable-jdk15

    Description

      Hi Apache,
      When I get an InputStream and try to close it before reading it to the end it simply does not get closed...
      here is a code example:

      =========================================================================================
      import java.io.IOException;
      import java.io.InputStream;
      import org.apache.commons.httpclient.HttpClient;
      import org.apache.commons.httpclient.methods.GetMethod;

      public class InputStreamCloseBug {

      public static void main(String[] args) {
      InputStream inputStream = null;
      HttpClient httpClient = new HttpClient();
      GetMethod getMethod = new GetMethod("http://dlc.sun.com/netbeans/download/5_5_1/fcs/200704122300/netbeans-5_5_1.tar.gz");
      try {
      httpClient.executeMethod(getMethod);
      inputStream = getMethod.getResponseBodyAsStream();
      for(int i = 0; i < 10; i++)

      { inputStream.read(); }

      inputStream.close(); // same if I use getMethod.releaseConnection()
      System.out.println("are we done yet ?"); // yeah, we are done after a few minutes - depending on the connection
      } catch (IOException ex)

      { ex.printStackTrace(); }

      }
      }
      =========================================================================================

      it takes as long as the stream is read to its end
      for me is about 6-8 minutes

      I've tried also the following

      =========================================================================================
      import java.io.IOException;
      import java.io.InputStream;
      import java.net.MalformedURLException;
      import java.net.URL;

      public class InputStreamClose {
      public static void main(String[] args) {
      URL url;
      try {
      url = new URL("http://dlc.sun.com/netbeans/download/5_5_1/fcs/200704122300/netbeans-5_5_1.tar.gz");
      InputStream input = url.openStream();
      for(int i = 0; i < 10; i++)

      { input.read(); }

      input.close();
      System.out.println("are we done yet!");
      } catch (MalformedURLException e)

      { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }

      }
      }
      =========================================================================================

      which works as expected
      it takes about 1 second

      I believe that this is a critical bug
      I haven't tried version 3.1RC1

      I hope this helps
      Happy bugfixing

      Regards
      MGP

      Attachments

        Activity

          People

            Unassigned Unassigned
            soulstealer Mario Pavlov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: