tst2005googlecode / step2

Automatically exported from code.google.com/p/step2
1 stars 0 forks source link

UrlHostMetaFetcher does not release the http connection if discovery fails (http response code != 200) #25

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use an invalid domain name and generate an auth request by calling
AuthRequestHelper.generateRequest
2. Reuse the same ConsumerHelper to generate an AuthRequestHelper and use
now a valid domain name and generate an auth request by calling
AuthRequestHelper.generateRequest
The discovery will fail and the following exception is the root cause:
Caused by: java.lang.IllegalStateException: Invalid use of
SingleClientConnManager: connection still allocated.
Make sure to release the connection before allocating another one.
    at
org.apache.http.impl.conn.SingleClientConnManager.getConnection(SingleClientConn
Manager.java:199)
    at
org.apache.http.impl.conn.SingleClientConnManager$1.getConnection(SingleClientCo
nnManager.java:173)
    at
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirecto
r.java:390)
    at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:6
41)
    at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:5
76)
    at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:5
54)
    at com.google.step2.http.DefaultHttpFetcher.fetch(DefaultHttpFetcher.java:76)
    at
com.google.step2.discovery.UrlHostMetaFetcher.getHostMeta(UrlHostMetaFetcher.jav
a:54)
    at
com.google.step2.discovery.ParallelHostMetaFetcher$FetcherThread.call(ParallelHo
stMetaFetcher.java:103)
    at
com.google.step2.discovery.ParallelHostMetaFetcher$FetcherThread.call(ParallelHo
stMetaFetcher.java:92)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
    at java.util.concurrent.FutureTask.run(FutureTask.java:123)
    at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:6
51)
    at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:676)
    ... 1 more

What is the expected output? What do you see instead?
The second discovery should succeed.

What version of the product are you using? On what operating system?
This issue has been reproduced with revision 435 and is also not fixed in
trunk.

Please provide any additional information below.
The fix is to close the InputStream returned from the response in a finally
block in the UrlHostMetaFetcher.

finally
    {
        if(response != null)
        {
            try
            {
                response.getContentAsStream().close();

            }
            catch(Exception ex)
            {
                //ignored
            }
        }
    }

This fixed the problem for us.

Original issue reported on code.google.com by felix.sc...@gmail.com on 7 Feb 2010 at 10:56

GoogleCodeExporter commented 9 years ago
This issue is related to Issue 24.

Original comment by felix.sc...@gmail.com on 7 Feb 2010 at 10:57

GoogleCodeExporter commented 9 years ago
I somehow can't reproduce this problem. The underlying appache http client is 
supposed to release the connection upon an error. 

Your stack trace is interesting - the line numbers in the apache http library 
don't 
match up with what I have. (I have javadocs or something on some of the lines 
that 
show up in your stack trace) 

I'm using the Apache http client library 4.0 beta 2. What version do you end up 
using? 

Original comment by balf...@google.com on 8 Feb 2010 at 10:49

GoogleCodeExporter commented 9 years ago
I'm using http client 4.0 final. (no beta).

May I ask how the http client will release the connection, if the http response 
code
is not 200?

Original comment by felix.sc...@gmail.com on 8 Feb 2010 at 11:09

GoogleCodeExporter commented 9 years ago
I looked at org.apache.http.impl.client.AbstractHttpClient#execute, which calls 
consumeContent() in case of error, which eventually calls releaseConnection().

Let me try the 4.0 final and see whether I can reproduce this.

Original comment by balf...@google.com on 9 Feb 2010 at 12:30

GoogleCodeExporter commented 9 years ago
Yes - I am able to reproduce it with 4.0 final. Will work on a fix now...

Original comment by balf...@google.com on 9 Feb 2010 at 1:04

GoogleCodeExporter commented 9 years ago
There are several execute methods on the AbstractHttpClient.
I don't think it calls the one which will calls consumeContent.
The DefaultHttpFetcher calls the execute method that takes an HttpUriRequest, 
this
will eventually lead to call the execute method which takes a target, request 
and
context, this method delegates to RequestDirector#execute.

The execute method that calls consumeContent needs a response ResponseHandler 
and is
not used.

Original comment by felix.sc...@gmail.com on 9 Feb 2010 at 1:14

GoogleCodeExporter commented 9 years ago
Fixed in http://code.google.com/p/step2/source/detail?r=479

Original comment by balf...@google.com on 9 Feb 2010 at 6:27

GoogleCodeExporter commented 9 years ago
Hi,

I am finding a similar error, this is my stack trace:

SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: Invalid use of SingleClientConnManager: 
connection still allocated.
Make sure to release the connection before allocating another one.
        at org.apache.http.impl.conn.SingleClientConnManager.getConnection(SingleClientConnManager.java:199)
        at org.apache.http.impl.conn.SingleClientConnManager$1.getConnection(SingleClientConnManager.java:173)
        at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:356)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
        at com.google.step2.http.DefaultHttpFetcher.fetch(DefaultHttpFetcher.java:76)
        at com.google.step2.discovery.UrlHostMetaFetcher.getHostMeta(UrlHostMetaFetcher.java:58)
        at com.google.step2.discovery.Discovery2.discoverOpEndpointsForSite(Discovery2.java:190)
        at com.google.step2.discovery.Discovery2$1.newStyleDiscovery(Discovery2.java:116)
        at com.google.step2.discovery.Discovery2$1.newStyleDiscovery(Discovery2.java:111)
        at com.google.step2.discovery.Discovery2$FallbackDiscovery.get(Discovery2.java:411)
        at com.google.step2.discovery.Discovery2.discover(Discovery2.java:345)
        at com.google.step2.AuthRequestHelper.getDiscoveryInformation(AuthRequestHelper.java:115)
        at com.google.step2.AuthRequestHelper.generateRequest(AuthRequestHelper.java:216)

is it the same problem? Does somebody else found this error?

Original comment by egarcia@stream18.com on 29 Feb 2012 at 9:36