hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Roberts <simon.robe...@fifthweb.net>
Subject Re: Running out of connections
Date Sun, 02 Feb 2003 21:46:24 GMT
I guess the problem is really mine.  I was somewhat expecting the connection
to be released after it gets a "connection: close".

    /**
     * A test that illustrates the problem with connections not being
recovered from a "Connection: close" response.
     */
    public void testConnectionPool()
            throws IOException, HttpException
    {
        final MultiThreadedHttpConnectionManager manager = new
MultiThreadedHttpConnectionManager();

        HttpClient httpClient = new HttpClient(manager);
        httpClient.getHostConfiguration().setHost("www.slashdot.org", 80,
"http");
        httpClient.setHttpConnectionFactoryTimeout(2000); // wait up to 2
seconds when getting a HttpConnection
        for (int i = 0; i < 30; i++) {
            HttpMethod method = new
GetMethod("http://www.slashdot.org/notfound");
            int res = httpClient.executeMethod(method);
            // System.gc();
            // method.releaseConnection();
        }
    }

Uncommenting either of the last two lines makes the problem go away...



----- Original Message -----
From: "Michael Becke" <becke@u.washington.edu>
To: "Commons HttpClient Project" <commons-httpclient-dev@jakarta.apache.org>
Sent: Sunday, February 02, 2003 6:18 AM
Subject: Re: Running out of connections


> Hello Simon,
>
> Sorry to be replying so late.  Connections are released when:
>
> 1) the response is fully read
> 2) the connection is manually released via
> HttpMethod.releaseConnection() or HttpConnection.releaseConnection()
> 3) the garbage collector runs and reclaims any connections that are no
> longer being used
>
> The most reliable way is to manually release the connection after use.
> This goes for successful or unsuccessful requests.  Can you send a
> sample of the code you are using that causes this problem?
>
> Mike
>
> On Wednesday, January 29, 2003, at 09:04 PM, Simon Roberts wrote:
>
> > Gidday,
> >
> > With the current CVS version, I seem to be having a problem where I
> > run out of connections to a server.  It happens if I do a bunch of
> > HTTP operations that fail (404, as it happens) and the reply include a
> > "Connection: close".  If no garbage-collect happens then the
> > connections are not freed!
> >
> > Shouldn't we expire them if we're running out of connections?
> >
> > Cheers, Simon
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
commons-httpclient-dev-help@jakarta.apache.org
>
>


Mime
View raw message