hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oleg Kalnichevski (JIRA)" <j...@apache.org>
Subject [jira] Resolved: (HTTPCLIENT-839) ThreadSafeClientConnManager blocks forever on getConnection()
Date Mon, 30 Mar 2009 15:48:50 GMT

     [ https://issues.apache.org/jira/browse/HTTPCLIENT-839?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Oleg Kalnichevski resolved HTTPCLIENT-839.
------------------------------------------

    Resolution: Invalid

@Matthias

> When POST-ing the data, ThreadSafeClientConnManager.getConnection() always blocks eternally

> during the third upload, waiting for a connection to become free (why does it wait anyway
when I told 
> it to use up to 10 connections, not just 2?

Because the HTTP spec states user agents should not use more than 2 concurrent connections
to the same host. In order to override this restriction one need to increase the number of
concurrent connections PER HOST. Setting the total maximum to a greater value is not sufficient.

> rendering the whole client object useless

My take is your application code does not correctly release connections back to the connection
pool. No connections in the pool, no party. 

See 'Ensuring release of low level resources' section of the tutorial for details:

http://wiki.apache.org/HttpComponents/HttpClientTutorial

If you are still convinced this is bug in HttpClient, please reproduce the issue (preferably
using the latest SVN snapshot) with the wire logging on and re-open the issue:

http://hc.apache.org/httpcomponents-client/logging.html

@Odi

> Anyway this connection manager should respect a timeout for getConnection(). Waiting
indefinitely is no good. 

Right you are, provided the time out has been set, which does not seem to be the case with
the code snippet posted

Oleg



> ThreadSafeClientConnManager blocks forever on getConnection()
> -------------------------------------------------------------
>
>                 Key: HTTPCLIENT-839
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-839
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpConn
>    Affects Versions: 4.0 Beta 2
>         Environment: Android 1.1 R1
>            Reporter: Matthias
>
> I have set up a HttpClient object with a ThreadSafeClientConnManager as follows:
>         BasicHttpParams httpParams = new BasicHttpParams();
>         ConnManagerParams.setMaxTotalConnections(httpParams, 10);
>         HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
>         HttpProtocolParams.setUserAgent(httpParams, HTTP_USER_AGENT);
>         SchemeRegistry schemeRegistry = new SchemeRegistry();
>         int port = prefs.isDebugMode() ? 3001 : 80;
>         schemeRegistry.register(new Scheme("http",
>                 PlainSocketFactory.getSocketFactory(), port));
>         ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(
>                 httpParams, schemeRegistry);
>         this.httpClient = new DefaultHttpClient(cm, httpParams);
> In one of my Android activities, I upload photos asynchronously using this client (i.e.
from different threads). When POST-ing the data, ThreadSafeClientConnManager.getConnection()
always blocks eternally during the third upload, waiting for a connection to become free (why
does it wait anyway when I told it to use up to 10 connections, not just 2?). ANY subsequent
attempt to call execute() on that client will block on that unreleased lock forever, rendering
the whole client object useless.
> Here is the code I use to dispatch the request:
>     private void sendPostRequest(String url, HttpEntity payload)
>             throws ConnectionFailedException, HttpResponseException {
>         try {
>             HttpPost request = new HttpPost(url);
>             request.setEntity(payload);
>             request.setHeader(HTTP_CONTENT_TYPE,
>                     payload.getContentType().getValue());
>             oauthConsumer.sign(url, request);
>             HttpResponse response = httpClient.execute(request,
>                     new BasicHttpContext());
>             validatePostResponse(response);
>         } catch (HttpResponseException e) {
>             throw e;
>         } catch (Exception e) {
>             throw new ConnectionFailedException(e);
>         }
>     }

-- 
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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message