Unable to connect couchbase server 3.0.1 with latest JDKversion 2.1.4

I am new to couchbase world. I am trying to connect to the couchbase server 3.0.1 with JDK 2.1.4.
I am not sure whether I am using correct version of JDK or not. The url is “http://xxxx.xxxx.net:8007/pools

Here is code I am using to connect to the couch-base bucket.

CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder().bootstrapCarrierDirectPort(8007)
                .bootstrapHttpDirectPort(8007).connectTimeout(10000).bootstrapHttpEnabled(true).build();
Cluster cluster = CouchbaseCluster.fromConnectionString(env, "http://xxxxxx.xx.ney:8007/pools");
bucket = cluster.openBucket(cacheConfig.getBucketName(), cacheConfig.getBucketPassword());

I got NumberFormatException. Then I removed the /pools from the Url and I am observing TimeoutException

Caused by: 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)

Any help will be much appreciated

Thanks

Hi @ndhilliprasad

Can you try with the other factory method for the cluster: CouchbaseCluster.create(env, "A.B.net") (either A.B.net the hostname, or the corresponding IP)?

How reliable is the network link between your client machine and the Couchbase node you bootstrap from? Any ping outliers for instance? 10s connection timeout is usually good for people who have timeouts with the 5s default though…

:warning: Note: despite changing ports on the server being possible, it is not generally recommended nor supported (as in getting support) as far as I know.

Hi Simon,

Facing the same issue. Not able to connect to couch 4.0 with JDK 2.1.4. Here is the test program

public static void main(String[] args) {
Cluster cluster = CouchbaseCluster.create(“10.126.110.181”);
Bucket bucket = cluster.openBucket(“session”,“1234”);
JsonObject user = JsonObject.empty().put(“firstname”,“Tom”).put(“lastname”,“Alter”).put(“job”, “faltu”);
JsonDocument doc = JsonDocument.create(“123”, user);
JsonDocument response = bucket.upsert(doc);
}

And the error is as under

INFO: Connected to Node 10.126.110.181
Exception in thread “main” 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 syslogs.Couchbase21.main(Couchbase21.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.util.concurrent.TimeoutException

Please help

Thanks
Abhay

@abhay8nitt can you please enable TRACE level logging and post the full logs somewhere? We need to see the communication between the nodes to find out what is causing the latency.

Looked into the source code of java client library. We need to tweak the CouchBaseEnvironment settings by disabling the bootstrapCarrier and enabling the bootstrapHttp. This will force the couch base library to use the com.couchbase.client.core.config.loader.HttpLoader for connecting to the couchbase pool

Here is the code snippet which worked for me

//Disable bootstrapCarrier, Enable bootstrapHttp,  set your http_port
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder().bootstrapCarrierEnabled(false).bootstrapHttpDirectPort("http_port").connectTimeout(9000).bootstrapHttpEnabled(true).build();
    
LOG.info("Creating couchbase cluster");
//couchbase url with out port and /pools
cluster = CouchbaseCluster.fromConnectionString(env, "http://xxxx.xxx.net"); 
    
LOG.info("Opening the bucket ......");
bucket = cluster.openBucket("bucket_name", "bucket_password");
LOG.info("Bucket Opened ......");

Thanks,
-Dhilli

@ndhilliprasad there is no reason you need to do that, what was the reasoning behind for you to disable carrier bootstrap? Note that if carrier fails, http is the fallback anyways (for backwards compat to 2.2 and earlier)

hi @dashchl please find below the link of the TRACE LEVEL logs.

Please do let me know if you need further information.
Appreciate your help!

@abhay8nitt it looks like it’s trying to do a reverse DNS lookup with takes quite some time (4 seconds)… you can either increase the connect timeout or double check your host file / dns settings

i have the same problem in the pass,you can run your client on linux,then you will find it is all right,or set connectTimeout(30000) running on windows

note that upcoming 2.2.0 will trigger earlier warnings of this kind of DNS reverse lookup errors by triggering eagerly and timing the lookup (will show up more explicitely that there may be a problem in the logs).
See https://issues.couchbase.com/browse/JVMCBC-229