Couchbase Parallel Timeout Error: Java SDK

I am working with java in a maven project. I used couchbase 2.3.1, but trying to solve this problem, I rolled back to 2.2.8 to no avail.

The problem I get is that while I get the date before my couchbase cluster, I see this a lot:

java.lang.RuntimeException: java.util.concurrent.TimeoutException at com.couchbase.client.java.util.Blocking.blockForSingle(Blocking.java:75) at com.couchbase.client.java.CouchbaseBucket.upsert(CouchbaseBucket.java:359) at com.couchbase.client.java.CouchbaseBucket.upsert(CouchbaseBucket.java:354) 

The following are the settings for my couchbase environment:

 CouchbaseEnvironment: {sslEnabled=false, sslKeystoreFile='null', sslKeystorePassword='null', queryEnabled=false, queryPort=8093, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=24, computationPoolSize=24, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=1, queryServiceEndpoints=1, searchServiceEndpoints=1, ioPool=NioEventLoopGroup, coreScheduler=CoreScheduler, eventBus=DefaultEventBus, packageNameAndVersion=couchbase-java-client/2.2.8 (git: 2.2.8, core: 1.2.9), dcpEnabled=false, retryStrategy=BestEffort, maxRequestLifetime=75000, retryDelay=ExponentialDelay{growBy 1.0 MICROSECONDS, powers of 2; lower=100, upper=100000}, reconnectDelay=ExponentialDelay{growBy 1.0 MILLISECONDS, powers of 2; lower=32, upper=4096}, observeIntervalDelay=ExponentialDelay{growBy 1.0 MICROSECONDS, powers of 2; lower=10, upper=100000}, keepAliveInterval=30000, autoreleaseAfter=2000, bufferPoolingEnabled=true, tcpNodelayEnabled=true, mutationTokensEnabled=false, socketConnectTimeout=1000, dcpConnectionBufferSize=20971520, dcpConnectionBufferAckThreshold=0.2, dcpConnectionName=dcp/core-io, callbacksOnIoPool=false, queryTimeout=75000, viewTimeout=75000, kvTimeout=2500, connectTimeout=5000, disconnectTimeout=25000, dnsSrvEnabled=false} 

I am not very sure what to look here. As far as I can tell, there should be a fairly decent connection between the server on which the application is running and the couchbase cluster. Any help or guidance on this will be helpful. Here is a snippet from which an error is thrown.

 LockableItem<InnerVertex> lv = this.getInnerVertex(id); lv.lock(); try { String content; try { content = mapper.writeValueAsString(lv.item); } catch (JsonProcessingException e) { LOG.warning(e.getMessage()); return; } RawJsonDocument d = RawJsonDocument.create(VertexId.toKey(id), content); bucket.upsert(d); } finally { lv.unlock(); } 
+7
source share
2 answers

I was looking for an answer. I have many solutions, everyone is talking about an exception. I also checked the JAR code, it is called that this is a timeout exception.

Cause analysis

The error occurred from the following couchbase section: https://github.com/couchbase/couchbase-java-client/blob/master/src/main/java/com/couchbase/client/java/util/Blocking.java# L71

 public static <T> T blockForSingle(final Observable<? extends T> observable, final long timeout, final TimeUnit tu) { final CountDownLatch latch = new CountDownLatch(1); TrackingSubscriber<T> subscriber = new TrackingSubscriber<T>(latch); observable.subscribe(subscriber); try { if (!latch.await(timeout, tu)) { // From here, this error occurs. throw new RuntimeException(new TimeoutException()); } } 

If the timeout expires, a TimeoutException is thrown, nested in the RuntimeException, for complete compatibility with the behavior of Observable.timeout (long, TimeUnit).

Link to the resource:

http://docs.couchbase.com/sdk-api/couchbase-java-client-2.2.0/com/couchbase/client/java/util/Blocking.html

Your configuration analysis and solution:

Your couchbase connection time is 5000ms or 5 seconds, which is the default for connection timeouts.

You need to increase this value to 10000ms or greater . Your problem will be resolved.

 //this tunes the SDK (to customize connection timeout) CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder() .connectTimeout(10000) //10000ms = 10s, default is 5s .build(); 

Complete solution

Simonbasle gave a complete solution in this tutorial:

From the short log, it looks like the SDK can connect to the host, but it takes a little longer to open the recycle bin. How good is the network connection between the two machines? Is it a virtual machine / cloud machine?

What you can try to do is increase the connection 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 CouchbaseEnvironment, CouchbaseCluster, and Bucket instances after creation (usually when they become static somewhere, or Spring singleton, etc.). They are thread-oriented and should be used together (and creating them is expensive in any case).

Link to the resource:

  1. Couchbase Connection Timeout Using Java SDK
+11
source

Thanks for the question and for @SkyWalker's answer. They helped when I came across this annoying timeout.

For Spring Data Couchbase 2, adding the following to application.properties solved this problem

 spring.couchbase.env.timeouts.connect=20000 
+2
source

Source: https://habr.com/ru/post/1260195/