[prev in list] [next in list] [prev in thread] [next in thread] 

List:       httpclient-users
Subject:    Re: java.io.IOException: Request already aborted - Why
From:       Oleg Kalnichevski <olegk () apache ! org>
Date:       2011-02-16 15:36:23
Message-ID: 1297870583.5455.92.camel () ubuntu
[Download RAW message or body]

On Wed, 2011-02-16 at 16:31 +0200, Maxim Veksler wrote:
> On Wed, Feb 16, 2011 at 3:14 PM, Oleg Kalnichevski <olegk@apache.org> wrote:
> > 
> > Once aborted a request cannot be executed again. Create a new HttpGet
> > instance for each request execution. They are cheap.
> > 
> > The problem is that HttpClient does not check whether or not a request
> > has been aborted prior to trying to execute it. Feel free to raise a
> > JIRA for this defect.
> > 
> > Oleg
> > 
> 
> I've implemented you comments and the execution has greatly improved.
> The code is working :)
> Please find code at
> https://gist.github.com/829061/50faa10a99aea3315449e13b4eaf558469795778
> 
> Several things still bug me:
> 
> 1. Why (as you can see from the attached below execution log) the code
> runs cleanly from ~20seconds and only then starts very frequently to
> throw ConnectionPoolTimeoutException ? Is this a problem on my end,
> the network or the linux kernel. I would appreciate if someone could
> download the HttpClientTest.java and run it to see if this behaviour
> reproduces for him as well. In my setup I've ran this now for ~50
> times and in all cases the errors start after ~20seconds.
> 

'httpGet = null' in the catch clause never gets executed because
HttpGet.abort() keeps throwing 'request already aborted' exception
causing your thread to spin like crazy. Rewrite you code to use a local
instance of HttpGet.


> 2. Do I need to call httpGet.abort(); on the old object is I'm going
> to create a new one on the next loop? (Please look at the code, it
> much easier just to show the logic then try and explain it here in
> text).
> 

No, you do not. You will be MUCH better off simply closing the input
stream in a finally clause, as shown here

http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientConnectionRelease.java



> 3. Is the code written correctly to reuse the connection,

See example above. I would also recommend re-using the same HttpClient
instance for all threads of execution.

> I would like
> to verify I'm send the GET events as quickly as possible - I will
> always be talking to the same RoutePath and Hench would like to take
> advantage of connection pooling. (After I get the buggy code to work
> correctly I will obviously raise the MaxPerRoute and the
> CONNECTION_TIMEOUT to reasonably values.
> 
> 4. You say:
> > Once aborted a request cannot be executed again. Create a new HttpGet
> > instance for each request execution. They are cheap.
> 
> What is considered resource intensive to create instances of? Is new
> DefaultHttpClient(); costly? 

Quite.

> Is new ThreadSafeClientConnManager();
> costly?
> 

Very much.

> 5. Please pay attention to my comment regarding the fact that my code
> is mostly based on the http client official documentation, I think
> it's worth updating it so that other people won't be confused. Would
> you like me to file a JIRA for it? Is there a code repository for the
> documentation, I would rather submit a patch.
> 

http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/src/docbkx/

We love patches ;-)

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic