hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: releasing streamed connections back to connection pool
Date Fri, 08 Apr 2016 10:04:45 GMT
On Fri, 2016-04-08 at 11:02 +0100, Tim Webster wrote:
> OK...so do you think I need to use this class to explicitly to consume the
> response?  I can see some methods on there for this.
> 
> Also - I think the call to PostMethod.releaseConnection() will still close
> it - do you have any idea if this should / should not be used?
> 

No, it will not.

Just make sure your code always consumes response content. 

Oleg

> Thanks,
> 
> 
> 
> 
> On Fri, Apr 8, 2016 at 10:46 AM, Bernd Eckenfels <ecki@zusammenkunft.net>
> wrote:
> 
> > It looks like the HttpResponseProxy will be responsible for releasing the
> > connection once the entity is consumed. Most likely by wrapping and
> > tracking the input stream.
> >
> >
> >
> >
> > Gruss
> > Bernd
> > --
> > http://bernd.eckenfels.net
> > From Win 10 Mobile
> >
> >
> >
> > *Von: *Tim Webster <tim.webster@gmail.com>
> > *Gesendet: *Freitag, 8. April 2016 11:42
> > *An: *httpclient-users@hc.apache.org
> > *Betreff: *releasing streamed connections back to connection pool
> >
> >
> >
> > Hi,
> >
> >
> >
> > I'm using Spring's HttpComponentsHttpInvokerRequestExecutor in my
> >
> > application, configured with a PoolingHttpClientConnectionManager.
> >
> >
> >
> > It all works fine, except that when a request is executed, the HTTP
> >
> > connection that was used is closed after every request.  This is a result
> >
> > of Spring calling HttpPost.releaseConnection().
> >
> >
> >
> > Ideally the connections would not be closed, but just released back to the
> >
> > connection pool.   This is especially important for HTTPS connections and
> >
> > the overhead of handshakes.
> >
> >
> >
> > My problem is, when httpPost.releaseConnection() is called, instead of just
> >
> > releasing the connection back to the pool, it closes it.  If you dig into
> >
> > the code you can see it ends up calling ConnectionHolder.cancel(), where
> >
> > ideally it would be calling ConnectionHolder.releaseConnection().
> >
> >
> >
> > I thought I could override the Spring code to NOT call
> >
> > HttpPost.releaseConnection(), figuring the connection manager would take
> >
> > care of releasing the connection itself, which it does, but not in my case
> >
> > because it is a streaming request (these are HTTP posts with input stream):
> >
> >
> >
> > From MainClientExec.java:
> >
> >
> >
> >
> >
> >             // check for entity, release connection if possible
> >
> >             final HttpEntity entity = response.getEntity();
> >
> >            if (entity == null || !entity.isStreaming()) {
> >
> >                 // connection not needed and (assumed to be) in re-usable
> >
> > state
> >
> >                 connHolder.releaseConnection();
> >
> >                 return new HttpResponseProxy(response, null);
> >
> >             } else {
> >
> >                 return new HttpResponseProxy(response, connHolder);
> >
> >             }
> >
> >
> >
> > So - I don't see a way with the API the way it is to do what I require,
> >
> > which is release the connection (without closing it) after consuming the
> >
> > response.
> >
> >
> >
> > I'm happy to provide more details/context if anyone can help....
> >
> >
> >
> > thanks,
> >
> >
> >



---------------------------------------------------------------------
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