You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Mario Pavlov (JIRA)" <ji...@apache.org> on 2007/08/11 10:43:43 UTC

[jira] Created: (HTTPCLIENT-681) InputStream obtained from HttpMethod.getResponseBodyAsStream() could not be closed before the end of the stream

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

                 Key: HTTPCLIENT-681
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-681
             Project: HttpComponents HttpClient
          Issue Type: Bug
    Affects Versions: 3.0.1
         Environment: FreeBSD-6.2-STABLE, diable-jdk15
            Reporter: Mario Pavlov


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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Closed: (HTTPCLIENT-681) InputStream obtained from HttpMethod.getResponseBodyAsStream() could not be closed before the end of the stream

Posted by "Roland Weber (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-681?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Roland Weber closed HTTPCLIENT-681.
-----------------------------------

    Resolution: Invalid

This works as designed. Closing the stream will read to the end of the message body in order to re-use the connection. Use HttpMethod.abort() to shut down the connection without reading to the end.

cheers,
  Roland


> InputStream obtained from HttpMethod.getResponseBodyAsStream() could not be closed before the end of the stream
> ---------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-681
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-681
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>    Affects Versions: 3.0.1
>         Environment: FreeBSD-6.2-STABLE, diable-jdk15
>            Reporter: Mario Pavlov
>
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Commented: (HTTPCLIENT-681) InputStream obtained from HttpMethod.getResponseBodyAsStream() could not be closed before the end of the stream

Posted by "Mario Pavlov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-681?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12519213 ] 

Mario Pavlov commented on HTTPCLIENT-681:
-----------------------------------------

omg
I'm very sorry
forgive my ignorance! :(

Regards
MGP

> InputStream obtained from HttpMethod.getResponseBodyAsStream() could not be closed before the end of the stream
> ---------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-681
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-681
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>    Affects Versions: 3.0.1
>         Environment: FreeBSD-6.2-STABLE, diable-jdk15
>            Reporter: Mario Pavlov
>
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org