Skip to content

PoolTimeoutException when connecting to Cassandra via Astyanax #86

Closed
akolyadenko opened this Issue Jul 22, 2012 · 8 comments

9 participants

@akolyadenko

I am trying to connect to local cassandra using astyanax, but constantly getting PoolTimeoutException. I am able to connect to cassandra using cli or hector client. Any idea what am I doing wrong?

Thanks.

My code:

val context = new AstyanaxContext.Builder()
.forCluster("cluster")
.forKeyspace(keyspace)
.withAstyanaxConfiguration(
new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.NONE)
)
.withConnectionPoolConfiguration(
new ConnectionPoolConfigurationImpl("ConnPool")
.setPort(9160)
.setMaxConnsPerHost(1)
.setMaxBlockedThreadsPerHost(1)
.setSeeds("127.0.0.1:9160")
.setConnectTimeout(10000)
)
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance())
context.start()
return context.getEntity()
Exception:

Exception in thread "main" java.lang.RuntimeException: com.netflix.astyanax.connectionpool.exceptions.PoolTimeoutException: PoolTimeoutException: [host=127.0.0.1(127.0.0.1):9160, latency=10004(10004), attempts=1] Timed out waiting for connection
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$7.getNextBlock(ThriftColumnFamilyQueryImpl.java:652)
at com.netflix.astyanax.thrift.ThriftAllRowsImpl$1.hasNext(ThriftAllRowsImpl.java:61)
at scala.collection.JavaConversions$JIteratorWrapper.hasNext(JavaConversions.scala:574)
at scala.collection.Iterator$class.foreach(Iterator.scala:772)
at scala.collection.JavaConversions$JIteratorWrapper.foreach(JavaConversions.scala:573)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:73)
at scala.collection.JavaConversions$JIterableWrapper.foreach(JavaConversions.scala:587)
at at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:60)
at scala.App$$anonfun$main$1.apply(App.scala:60)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:76)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:30)
at scala.App$class.main(App.scala:60)
at Caused by: com.netflix.astyanax.connectionpool.exceptions.PoolTimeoutException: PoolTimeoutException: [host=127.0.0.1(127.0.0.1):9160, latency=10004(10004), attempts=1] Timed out waiting for connection
at com.netflix.astyanax.connectionpool.impl.SimpleHostConnectionPool.waitForConnection(SimpleHostConnectionPool.java:201)
at com.netflix.astyanax.connectionpool.impl.SimpleHostConnectionPool.borrowConnection(SimpleHostConnectionPool.java:158)
at com.netflix.astyanax.connectionpool.impl.RoundRobinExecuteWithFailover.borrowConnection(RoundRobinExecuteWithFailover.java:60)
at com.netflix.astyanax.connectionpool.impl.AbstractExecuteWithFailoverImpl.tryOperation(AbstractExecuteWithFailoverImpl.java:50)
at com.netflix.astyanax.connectionpool.impl.AbstractHostPartitionConnectionPool.executeWithFailover(AbstractHostPartitionConnectionPool.java:229)
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$7.getNextBlock(ThriftC

@JimKerwood

I coppied in your code and it looks fine w/ the addition of a ; before the context.start
Try changing your monitor to
.withConnectionPoolMonitor(new Slf4jConnectionPoolMonitorImpl())
and you should get a logged reason on why it isn't connecting correctly.

Or try debugging thru to see some of the inner workings.

@jbellmann

Hi,

had the same problem when I tried Astyanax first time today with latest version (1.0.6) found in Maven-Central.
Switching to the Slf4jConnectionPoolMonitorImpl does not gave me more hints to the problem.

After looking to some Unit-Tests of Astyanax to make sure I'm not totally stupid and doing the right thing, I just switched back to version 1.0.0. And you may don't believe it my code was working. Yeah.

I go version by version to see when it breaks again. At 1.0.4 it stops working.

Result: 1.0.0, 1.0.1, 1.0.2, 1.0.3 all working. 1.0.4., 1.0.5, 1.0.6 NOT WORKING.

JDK:

bellombp:cassandra-session-manager-astyanax jbellmann$ java -version
java version "1.7.0_06"
Java(TM) SE Runtime Environment (build 1.7.0_06-b24)
Java HotSpot(TM) 64-Bit Server VM (build 23.2-b09, mixed mode)

maven-compiler-plugin was set to 1.6 for 'source' and 'target'

You can have a look at the sources here

Cheers
Joerg

@iqdk
iqdk commented Aug 31, 2012

Hi,

I was getting the same error... Debugging into the Astyanax code shows this error:

java.lang.IncompatibleClassChangeError: class org.apache.cassandra.thrift.Cassandra$Client has interface org.apache.thrift.TServiceClient as super class

Just curious, what version of Cassandra did you use?
We just tried 1.1.2 (released about a month ago).

Thanks,
Dan

@jbellmann

Hi,

I use the cassandra-maven-plugin in version 1.0.0-1 which uses cassandra 1.0 I think. I tried to update to a newer version but I had trouble with some 'snappy-stuff that is not in the library path' and did not found a fast solution. So I run cassandra 1.0 with the above mentioned versions of astyanax.

Maybe there are some problems with the Thrift dependencies between client and cassandra.
I will investigate some time next week to find out more hopefully.

Hope that answers your question.

Cheers
Joerg

@ivanvel
ivanvel commented Nov 1, 2012

Hi guys, just a guess, is your cassandra configured properly so it allows diffferent IPs (default one is 127.0.0.1)?
Check rpc_address property in cassandra.yaml as only those specified there can be used by clients whether it's astyanax, cqlsh or cli.

@elandau elandau closed this Nov 15, 2012
@raresp
raresp commented Dec 14, 2012

I am having the same problem.
Astyanax times out while the cli and cqlsh work just fine.

Caused by: org.apache.thrift.transport.TTransportException: java.net.SocketTimeoutException: Read timed out
at org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:129)
at org.apache.thrift.transport.TTransport.readAll(TTransport.java:84)
at org.apache.thrift.transport.TFramedTransport.readFrame(TFramedTransport.java:129)
at org.apache.thrift.transport.TFramedTransport.read(TFramedTransport.java:101)
at org.apache.thrift.transport.TTransport.readAll(TTransport.java:84)
at org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:378)
at org.apache.thrift.protocol.TBinaryProtocol.readI32(TBinaryProtocol.java:297)
at org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:204)
at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:69)
at org.apache.cassandra.thrift.Cassandra$Client.recv_get_indexed_slices(Cassandra.java:753)
at org.apache.cassandra.thrift.Cassandra$Client.get_indexed_slices(Cassandra.java:737)
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$5$1.internalExecute(ThriftColumnFamilyQueryImpl.java:524)

Why was this issue closed?

@FuadEfendi

there are two scenario here:
1. Your Cassandra listens on IP / Port numbers which are completely different from your test code client; in this case you will constantly get PoolTimeoutException

  1. java.net.SocketTimeoutException: Read timed out
  2. try to increase it, .setSocketTimeout(30000), your queries could be slow:

    .withConnectionPoolConfiguration(
    new ConnectionPoolConfigurationImpl(TEST_CLUSTER_NAME
    + "_" + TEST_KEYSPACE_NAME)
    .setSocketTimeout(30000)
    .setMaxTimeoutWhenExhausted(2000)
    .setMaxConnsPerHost(20)
    .setInitConnsPerHost(10)
    .setSeeds(SEEDS))

@diguage
diguage commented Jan 4, 2015

I had the same error.Now, it is OK.

The main problem is that the configuration is wrong.

My configuration is as following:

My visual machine ip is 192.168.11.11.My cassandra was installed into the machine.So, I configurate thar

listen_address: 192.168.11.11
rpc_address: 0.0.0.0
broadcast_rpc_address: 192.168.11.11

That is OK。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.