hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nir Dweck <n...@vasco-de.com>
Subject RE: connections left in CLOSE_WAIT state
Date Thu, 20 Feb 2014 12:54:26 GMT
Hi,
OK I missed the fact that the channel is returned to the pool only after I consume the entity,
I thought it is retuned when the httpclient.execute() returns.

Regards,
Nir


-----Original Message-----
From: Oleg Kalnichevski [mailto:olegk@apache.org] 
Sent: Thursday, February 20, 2014 12:04 PM
To: HttpClient User Discussion
Subject: Re: connections left in CLOSE_WAIT state

On Thu, 2014-02-20 at 09:46 +0000, Nir Dweck wrote:
> Hi,
> Thanks for the tip, it solve my issue. 
> However there is one point I still don't understand.
> Say I used a connection, and returned it to the pool.
> During the time the connection is in the pool, the server sent a FIN message, so the
socket changed to CLOSE_WAIT.
> Now when I need to send another request to the same address, I would 
> expect the pool to get that connection, check it and see that it 
> should be closed,

There is no way to find out whether or not a socket needs to be closed with blocking i/o other
than trying to read from it. This is essentially what the so called stale connection check
does.


>  close it (send FIN to the server), create a new connection and return it to me.
> If that was the case then there would have been times where I would see connections in
CLOSE_WAIT but when new request appear they should have disappeared.
> What I saw is the number of CLOSE_WAIT sockets raising all the time and when a socket
reached that state it was never released.
> 
> What am I missing?

Make sure your code is not leaking connections.

Oleg

> Regards,
> Nir
> 
> -----Original Message-----
> From: Oleg Kalnichevski [mailto:olegk@apache.org]
> Sent: Wednesday, February 19, 2014 1:18 PM
> To: HttpClient User Discussion
> Subject: Re: connections left in CLOSE_WAIT state
> 
> On Wed, 2014-02-19 at 10:33 +0000, Nir Dweck wrote:
> > Hi,
> > I am using httpclient version 4.2.3.
> > I did a split proxy, which receives an HTTP requests, opens its body in order to
log its content and then sends the content in two requests, one for the local host server
and the other to a different server running a newer version of our software.
> > this is the code I used to create the http client:
> >                         PoolingClientConnectionManager mngr = new PoolingClientConnectionManager();
> >                         mngr.setMaxTotal(400);
> >                         mngr.setDefaultMaxPerRoute(200);
> >                         m_http = new DefaultHttpClient(mngr);
> >                         m_http.getParams().setParameter(CoreProtocolPNames.USER_AGENT,
"phytech proxy");
> >                         
> > m_http.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIME
> > OUT, 10000);
> >                         
> > m_http.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
> > 5000);
> > 
> > When I need to send a request to the remote host, I take a thread from a thread
pool which will perform the operation asynchronously.
> > The proxy and the old server are running windows and the new server is on a Linux
machine.
> > The problem is I get tones of connections with the remote server which are stuck
in CLOSE_WAIT state and never get released (none with the local host - I think it is related
to the fact the local machine is windows).
> > When I look at the sniffer I don't see any FIN message coming out of my client,
although I set SO_TIMEOUT to 5 seconds and there were more than 5 seconds of inactivity.
> > Any idea what am I doing wrong and how to solve it?
> > Thanks,
> > Nir
> 
> Most likely you need to pro-actively evict stale / idle connections 
> from the connection pool
> 
> http://hc.apache.org/httpcomponents-client-4.2.x/tutorial/html/connmgm
> t.html#d5e652
> 
> Oleg
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 



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

Mime
View raw message