hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: keep alivee connection timeout error on httpasyncclient-4.0.1
Date Thu, 24 Jul 2014 11:49:07 GMT
On Wed, 2014-07-23 at 20:31 +0800, qxw_2000@sina.com wrote:
> Hi, all
> 
> 
> 	When I use httpasyncclient-4.0.1 for developing, I find one question for keep alive
connection.
> 
> 
> 	After processing one request, the connection manager will retrieve the connection. 
> 
> 
> 	However, the ConnectionKeepAliveStrategy is not take effect, the connection will be
timeout using socket timeout value, not until the value strategy is given.
> 
> 
> 	By reading httpasyncclient code, I find the Deprecated class PoolingClientAsyncConnectionManager
do the right thing:
>             try {
>                 if (managedConn.isOpen() && !managedConn.isMarkedReusable())
{
>                     try {
>                         managedConn.shutdown();
>                     } catch (final IOException iox) {
>                         if (this.log.isDebugEnabled()) {
>                             this.log.debug("I/O exception shutting down released connection",
iox);
>                         }
>                     }
>                 }
>                 if (managedConn.isOpen()) {
>                     entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
>                     if (this.log.isDebugEnabled()) {
>                         String s;
>                         if (keepalive > 0) {
>                             s = "for " + keepalive + " " + tunit;
>                         } else {
>                             s = "indefinitely";
>                         }
>                         this.log.debug("Connection " + format(entry) + " can be kept
alive " + s);
>                     }
>                     // Do not time out pooled connection
>                     managedConn.setSocketTimeout(0);
>                 }
>             } finally {
>                 this.pool.release(managedConn.detach(), managedConn.isMarkedReusable());
>             }
> 
> 
> 
> 
> 	The new PoolingNHttpClientConnectionManager class do not contain this code. So the connection
will use the socket timeout config, close shortly. Then I add same code on PoolingNHttpClientConnectionManager,
everything goes ok now...
>             try {
>                 if (conn.isOpen()) {
>                     entry.setState(state);
>                     log.debug("yyyyy keepalive: " + keepalive);
>                     entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
>                     if (this.log.isDebugEnabled()) {
>                         final String s;
>                         if (keepalive > 0) {
>                             s = "for " + (double) keepalive / 1000 + " seconds";
>                         } else {
>                             s = "indefinitely";
>                         }
>                         this.log.debug("Connection " + format(entry) + " can be kept
alive " + s);
>                         conn.setSocketTimeout(0);
>                     }
>                 }
>             } finally {
>                 this.pool.release(entry, conn.isOpen() && entry.isRouteComplete());
>                 if (this.log.isDebugEnabled()) {
>                     this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
>                 }
>             }
> 
> 
> 	Can anyone tell me whether I do the right change ? 
> 


Connection re-use and keep-alive logic got moved to the MainClientExec
class. 

Hope this helps

Oleg



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


Mime
View raw message