Unable to connect to DB - java.util.concurrent.TimeoutException

Hi,
I keep getting java.lang.RuntimeException: java.util.concurrent.TimeoutException when trying to connect

I just installed Couchbase for evaluation. I 'm using 3.0.3-1716 Enterprise Edition (build-1716) on Redhat 6.0 as the server and java-client 2.1.4 SDK running on WIN 7 with JDK 7 as the client
I followed the instructions of Hello Couchbase Example from http://docs.couchbase.com/developer/java-2.1/hello-couchbase.html

import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.CouchbaseCluster;

public class NoSQLTest {

	public static void main(String[] args) {
		try {
			System.out.println("Create connection");
			Cluster cluster = CouchbaseCluster.create("10.115.224.94");
			System.out.println("Try to openBucket");
			Bucket bucket = cluster.openBucket("beer-sample");
			System.out.println("disconnect");
			cluster.disconnect();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}

The output is:

 Create connection
- CouchbaseEnvironment: {sslEnabled=false, sslKeystoreFile='null', sslKeystorePassword='null', queryEnabled=false, queryPort=8093, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=4, computationPoolSize=4, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=1, queryServiceEndpoints=1, ioPool=NioEventLoopGroup, coreScheduler=CoreScheduler, eventBus=DefaultEventBus, packageNameAndVersion=couchbase-java-client/2.1.4 (git: 2.1.4), dcpEnabled=false, retryStrategy=BestEffort, maxRequestLifetime=75000, retryDelay=ExponentialDelay{growBy 1.0 MICROSECONDS; lower=100, upper=100000}, reconnectDelay=ExponentialDelay{growBy 1.0 MILLISECONDS; lower=32, upper=4096}, observeIntervalDelay=ExponentialDelay{growBy 1.0 MICROSECONDS; lower=10, upper=100000}, keepAliveInterval=30000, autoreleaseAfter=2000, bufferPoolingEnabled=true, queryTimeout=75000, viewTimeout=75000, kvTimeout=2500, connectTimeout=5000, disconnectTimeout=25000, dnsSrvEnabled=false}
Try to openBucket
- Connected to Node 10.115.224.94
java.lang.RuntimeException: java.util.concurrent.TimeoutException
	at com.couchbase.client.java.util.Blocking.blockForSingle(Blocking.java:93)
	at com.couchbase.client.java.CouchbaseCluster.openBucket(CouchbaseCluster.java:108)
	at com.couchbase.client.java.CouchbaseCluster.openBucket(CouchbaseCluster.java:99)
	at com.couchbase.client.java.CouchbaseCluster.openBucket(CouchbaseCluster.java:89)
	at com.couchbase.client.java.CouchbaseCluster.openBucket(CouchbaseCluster.java:79)
	at comverse.cpo.foss.test.NoSQLTest.main(NoSQLTest.java:14)
Caused by: java.util.concurrent.TimeoutException
	... 6 more

I checked with telnet and port 11211 is open
Can some one advise what can be the problem?

Thanks in advance
Sagi

Hi @ssefer
From the short log, it looks like the SDK is able to connect to the node, but takes a little much time to open the bucket. How good is the network link between the two machines? Is this a VM/cloud machine?

What you can try to do is increase the connect timeout:

public class NoSQLTest {
public static void main(String[] args) {
        try {
            //this tunes the SDK (to customize connection timeout)
            CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
                    .connectTimeout(10000) //10000ms = 10s, default is 5s
                    .build();
            System.out.println("Create connection");
            //use the env during cluster creation to apply
            Cluster cluster = CouchbaseCluster.create(env, "10.115.224.94");
            System.out.println("Try to openBucket");
            Bucket bucket = cluster.openBucket("beer-sample"); //you can also force a greater timeout here (cluster.openBucket("beer-sample", 10, TimeUnit.SECONDS))
            System.out.println("disconnect");
            cluster.disconnect();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}

As a side note, you should always reuse the CouchbaseEnvironment, CouchbaseCluster and Bucket instances once created (usually by making them public static somewhere, or a Spring singleton, etc…).
These are thread safe and should be shared (and they are expensive to create anyway).

1 Like

Hi @simonbasle
Thanks, that solve the problem :smiley:

great! you may have to fine tune the delay though, and try to find out if it is because of, say, a high latency in your network link.

A post was split to a new topic: NoClassDefFoundError on CoreEnvironment

It gives me an Error “CouchbaseEnvironment” Symbol is not found…please help me with this