aws-sdk-java: Timeout waiting for connection from pool

Timeout waiting for connection from pool

! org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool
! at org.apache.http.impl.conn.PoolingClientConnectionManager.leaseConnection(PoolingClientConnectionManager.java:226) 
! at org.apache.http.impl.conn.PoolingClientConnectionManager$1.getConnection(PoolingClientConnectionManager.java:195) 
! at sun.reflect.GeneratedMethodAccessor22.invoke(Unknown Source) ~[na:na]
! at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_11]
! at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_11]
! at com.amazonaws.http.conn.ClientConnectionRequestFactory$Handler.invoke(ClientConnectionRequestFactory.java:70)
! at com.amazonaws.http.conn.$Proxy70.getConnection(Unknown Source) ~[na:na]
! at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:423)
! at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
! at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
! at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
! at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:446)
! at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:256)
! at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:2908)
! at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.query(AmazonDynamoDBClient.java:1064)

A check on connections on a server showed a lot of close waits -

netstat -a  | grep CLOSE_WAIT | wc -l 
> 987

which is often indicative of an apache client request not having a close() called. Checking cloudwatch, there was a corresponding latency increase in DDB around the time we saw this (up to 8s).

There wasn’t a change in how we call DynamoDB at the time. I am wondering if there is an issue in the client if/when the server latencies are high such that connections don’t get closed?

This happened on 1.8.3. We’re going to upgrade to 1.8.9.1, but it’s hard to tell if related code was changed, the release diffs are too big to review easily 😃

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 22 (8 by maintainers)

Most upvoted comments

@ferozed Are you perhaps using the streaming API to read S3 objects but forget to close the S3Object after you consume the content?

http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/model/S3Object.html#getObjectContent()

FYI: I found that I was able to work around getting this error by using AmazonS3Client.getObjectAsString method, which has a finally block with a close on it, as opposed to using AmazoneS3Client.getObject , which doesn’t seem to have the same closing feature.

} finally {
            IOUtils.closeQuietly(object, log);
        }

@agargi is correct - if you ever have a reference to an S3Object, you MUST close it, otherwise you’re potentially leaking an HTTP connection.

Also, if you’re just writing the object contents to disk, then you can use TransferManager, or one of the over versions of getObject in AmazonS3Client that take in a file and will perform the file write for you. That would prevent you from ever having to manage/close the S3Object streams.