Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Bug: HttpClient
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
tomgibara  
View profile  
 More options Dec 30 2007, 5:41 pm
From: tomgibara <tomgib...@hotmail.com>
Date: Sun, 30 Dec 2007 14:41:15 -0800 (PST)
Local: Sun, Dec 30 2007 5:41 pm
Subject: Bug: HttpClient
Phew... this has taken me many many hours to track down, mostly
because I stumbled across it in the middle of some dense resource
management code - and the problem is actually very far from there...

Here's a test method (with a trivial subsidiary method) that makes two
sequential requests to the same server using two different GetMethod
objects sharing one HttpClient object - I presume a very common
situation:

    private void testSequentialGet(String url) {
        HttpClient client = new HttpClient();
        byte[] buffer = new byte[8192];
        try {

            GetMethod get1 = new GetMethod(url);
            try {
                int status = client.executeMethod(get1);
                Log.i("test", "Status for " + url + " (1) = " + status);
                long read = exhaust(get1.getResponseBodyAsStream(),
buffer);
                Log.i("test", "Bytes read for " + url + " (1) = " +
read);
            } finally {
                get1.releaseConnection();
            }

            GetMethod get2 = new GetMethod(url);
            try {
                int status = client.executeMethod(get2);
                Log.i("test", "Status for " + url + " (2) = " + status);
                long read = exhaust(get2.getResponseBodyAsStream(),
buffer);
                Log.i("test", "Bytes read for " + url + " (2) = " +
read);
            } finally {
                get2.releaseConnection();
            }
        } catch (HttpException e) {
            Log.i("test", "Test of " + url + " failed with an HTTP
exception.", e);
        } catch (IOException e) {
            Log.i("test", "Test of " + url + " failed with an IO
exception.", e);
        }
    }

    private static long exhaust(final InputStream in, byte[] buffer)
throws IOException {
        long read = 0L;
        try {
            for (int r = 0; r >= 0; r = in.read(buffer)) read += r;
        } finally {
            try {
                in.close();
            } catch (IOException e) { }
        }
        return read;
    }

We can call this method (using the latest version of the emulator to-
date: m3-rc37) with a number of different URLs:

testSequentialGet("http://www.google.com");
testSequentialGet("http://www.apache.org");
testSequentialGet("http://www.microsoft.com");

and the resulting output in the log is:

I/test(656): Status for http://www.google.com (1) = 200
I/test(656): Bytes read for http://www.google.com (1) = 5424
I/test(656): Status for http://www.google.com (2) = 200
I/test(656): Bytes read for http://www.google.com (2) = 5424

I/test(656): Status for http://www.apache.org (1) = 200
I/test(656): Bytes read for http://www.apache.org (1) = 17409
I/test(656): Test of http://www.apache.org failed with an IO
exception.

I/test(656): Test of http://www.microsoft.com failed with an IO
exception.
I/test(656): java.io.InterruptedIOException: Read timed out

Repeated requests to Google work as expected. The first request to
Apache (running a development version of the Apache webserver)
succeeds but the second request fails. The first request to Microsoft
(running IIS7) fails. These are, as far as I can confirm, entirely
reproducible exceptions, and I don't think I'm making any mistakes in
my use of the Jakarta HttpClient library. Nor am I behind a proxy
server.

Anecdotally, I think that the problems may be related to HTTP/1.1 Keep
Alives. I have three pieces of evidence for this. Firstly, disabling
Keep Alives on my local development server (which is where I first
encountered the problem) seemed to remove the exception. Secondly, I
briefly looked online for a popular site that runs with Keep Alives
disabled, I found Slashdot (http://slashdot.org) which runs in this
way (on an Apache webserver); repeated requests to the /. homepage do
not trigger an exception. Thirdly, the exception itself (which I don't
have the motivation to investigate further at this time) is the same
in every case and looks like this:

I/test(680):     at
org.apache.harmony.luni.platform.OSFileSystem.readImpl(Native Method)
I/test(680):     at
org.apache.harmony.luni.platform.OSFileSystem.read(OSFileSystem.java:
150)
I/test(680):     at java.io.FileInputStream.read(FileInputStream.java:
306)
I/test(680):     at
java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:173)
I/test(680):     at
java.io.BufferedInputStream.read(BufferedInputStream.java:228)
I/test(680):     at
org.apache.commons.httpclient.HttpConnection.isStale(HttpConnection.java:
509)
I/test(680):     at
org.apache.commons.httpclient.HttpConnection.closeIfStale(HttpConnection.ja va:
434)
I/test(680):     at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMetho dDirector.java:
381)
I/test(680):     at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDi rector.java:
170)
I/test(680):     at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:
398)
I/test(680):     at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:
326)

Checking for stale connections might have some interaction with
persistent connections?

There are numerous plausible workarounds; if this bug is not to be
fixed soon, I welcome any advice on the best workaround to adopt since
I don't have a handle on its scope.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wink Saville  
View profile  
 More options Dec 30 2007, 6:15 pm
From: Wink Saville <w...@saville.com>
Date: Sun, 30 Dec 2007 15:15:26 -0800
Local: Sun, Dec 30 2007 6:15 pm
Subject: Re: [android-developers] Bug: HttpClient
Posted to android-bugs@googlegroups.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
glorgster@gmail.com  
View profile  
 More options Dec 30 2007, 10:54 pm
From: "glorgs...@gmail.com" <glorgs...@gmail.com>
Date: Sun, 30 Dec 2007 19:54:06 -0800 (PST)
Local: Sun, Dec 30 2007 10:54 pm
Subject: Re: Bug: HttpClient
Hi,

May you sniff http request header?

http/1.1 assumes that if no keep-alive option specified in request
header, then "Connection: keep-alive" suggested by default.

However, when I've used my own http-client with Apache 1.3, omitting
of this option lead me to similar problem (connection was closed on
next requests), even if MaxKeepAliveRequests and KeepAliveTimeout were
set to reasonable values.

This, of course, cannot explain, why microsoft.com is not working. May
be really - timeout, exactly as said? May you check netstat for
connection states or monitor connections somehow else, tcpdump all
related packets and etc?

---
Happy New Year,
Alexey
http://en.triled.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fry  
View profile  
 More options Jan 19 2008, 6:51 pm
From: fry <bender...@gmail.com>
Date: Sat, 19 Jan 2008 15:51:56 -0800 (PST)
Local: Sat, Jan 19 2008 6:51 pm
Subject: Re: Bug: HttpClient
Hi! I had the same problem - the workaround is rather simple:

httpclient.getHttpConnectionManager().getParams().setStaleCheckingEnabled(f alse);

On Dec 31 2007, 1:41 am, tomgibara <tomgib...@hotmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tomgibara  
View profile  
 More options Jan 20 2008, 3:08 pm
From: tomgibara <tomgib...@hotmail.com>
Date: Sun, 20 Jan 2008 12:08:20 -0800 (PST)
Local: Sun, Jan 20 2008 3:08 pm
Subject: Re: Bug: HttpClient
Thanks for that workaround, I'll try it out. As I hinted in my
posting, I was too tired at the time to pursue it further and have
ignored the problem since then (side stepping it mostly by not reusing
HttpClient instances) so I'm glad you took the time to post your
workaround.

The docs for the method state:

Defines whether stale connection check is to be used. Disabling stale
connection check may result in slight performance improvement at the
risk of getting an I/O error when executing a request over a
connection that has been closed at the server side.

I presume this is referring to the situation when a server times-out a
'kept-alive' HTTP session. I don't know how often that will happen
since I expect it depends on the behaviour of the HttpClient library
code. Anyway, it's got to be better than the workaround I've been
using.

On Jan 19, 11:51 pm, fry <bender...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fry  
View profile  
 More options Jan 21 2008, 7:41 am
From: fry <bender...@gmail.com>
Date: Mon, 21 Jan 2008 04:41:46 -0800 (PST)
Local: Mon, Jan 21 2008 7:41 am
Subject: Re: Bug: HttpClient
I meant it is simple that it is just one line code, but it was not
really simple to find it :)

As for the disabling StaleChecking, currently I really do not care if
it would bring some instability in some cases - for me it is more than
enough that it just works at current moment - I could not find even
such workarounds for many other android bugs and limitations I have
met. This is a bug, and I hope it would be fixed - in my case I have
met it even not in my code, but in the 3rd party library I wanted to
use - luckily it has GPL license and I could create a modified version
that works on android for me with stale checking disabled.

On Jan 20, 11:08 pm, tomgibara <tomgib...@hotmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
baker  
View profile  
 More options Jan 23 2008, 10:46 pm
From: baker <craigbba...@gmail.com>
Date: Wed, 23 Jan 2008 19:46:50 -0800 (PST)
Local: Wed, Jan 23 2008 10:46 pm
Subject: Re: Bug: HttpClient
I really hope this is fixed soon, java's URLConnection is such a dog
of an implementation, not being able to handle timeouts is such a
pain.

I had no success with .setStaleCheckingEnabled(false);

Craig.

On Jan 21, 11:41 pm, fry <bender...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fry  
View profile  
 More options Jan 24 2008, 4:54 am
From: fry <bender...@gmail.com>
Date: Thu, 24 Jan 2008 01:54:32 -0800 (PST)
Local: Thurs, Jan 24 2008 4:54 am
Subject: Re: Bug: HttpClient
Do you have the same exception stack trace? I was able to find the
workaround because I saw the following line in the stack trace:

I/test(680):
atorg.apache.commons.httpclient.HttpConnection.isStale(HttpConnection.java:
509)

You can see that the exception came from the isStale() call and went
deeper to some kind of file system native call problem. So this gave
me the idea, that if I would switch the stale checking off, this
method would not be called and problem would not appear - and luckily
this helped. Probably you have another kind of problem, or after
switching off stale checking another problem showed itself, or you are
switching it off not for all httpclient objects.

I/test(680):     at
org.apache.harmony.luni.platform.OSFileSystem.readImpl(Native Method)
I/test(680):     at
org.apache.harmony.luni.platform.OSFileSystem.read(OSFileSystem.java:
150)
I/test(680):     at java.io.FileInputStream.read(FileInputStream.java:
306)
I/test(680):     at
java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:173)
I/test(680):     at
java.io.BufferedInputStream.read(BufferedInputStream.java:228)
I/test(680):
atorg.apache.commons.httpclient.HttpConnection.isStale(HttpConnection.java:
509)

On Jan 24, 6:46 am, baker <craigbba...@gmail.com> wrote:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
baker  
View profile  
 More options Jan 27 2008, 8:28 pm
From: baker <craigbba...@gmail.com>
Date: Sun, 27 Jan 2008 17:28:21 -0800 (PST)
Local: Sun, Jan 27 2008 8:28 pm
Subject: Re: Bug: HttpClient
Ok I managed to get HttpClient working, still think it is a little
flaky.

I had to increase the default timeout on the connection otherwise it
would throw a timeout exception. A little odd that the default timeout
is triggered when making a local http connection.

connectionManager.getParams().setConnectionTimeout(30*1000);

Thanks

Craig.

On Jan 24, 8:54 pm, fry <bender...@gmail.com> wrote:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »