hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Webster <tim.webs...@gmail.com>
Subject releasing streamed connections back to connection pool
Date Fri, 08 Apr 2016 09:41:50 GMT

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

I'm happy to provide more details/context if anyone can help....


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message