What is best way to stop the connection retry in Java SDK 2.1.4

#1

I have

// setup
env = DefaultCouchbaseEnvironment
.builder()
.retryStrategy(FailFastRetryStrategy.INSTANCE)
.build();
but is not working

Im a using <couchbase.driver.version>2.1.4</couchbase.driver.version>

Aug 31, 2015 7:10:54 PM com.couchbase.client.core.logging.Slf4JLogger warn
WARNING: [null][KeyValueEndpoint]: Could not connect to endpoint, retrying with delay 4096 MILLISECONDS:
java.net.ConnectException: Connection refused: uat.betiator.com/192.168.1.223:11210
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)
at com.couchbase.client.deps.io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:208)
at com.couchbase.client.deps.io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:281)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at com.couchbase.client.deps.io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
at com.couchbase.client.deps.io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
at java.lang.Thread.run(Thread.java:745)

#2

I just want to make one connection request and I will deal with the fail .
Use Case a user enters host IP to connect to make a user defined query but enters an invalid IP address .

#3

@GeorgeLeon in what context does it happen? Normally if you can’t bootstrap it will stop reconnecting - any code you can show us to clear it up further?

#4

Hi @daschl

What is happening is that if the Host Ip is invalid say e.g. 192.1A68.1.10ASD or a non existing / reachable IP it closes OK .

But if the host IP is say 192.168.1.10 and this server does not have couchbase with query on it my program loops and retries connections.

One way to test it is to try to conenct to a data service only node

Here is my code

void runAction(){
    CouchbaseEnvironment env=null;
    Cluster cluster = null;
    Bucket bucket= null;
    try {

        // setup
        env = DefaultCouchbaseEnvironment
                .builder()
                .retryStrategy(FailFastRetryStrategy.INSTANCE)
                .build();

        cluster = CouchbaseCluster.create(env, hostFld.getValue().trim());
        bucket = cluster.openBucket(bucketFld.getValue().trim());

        String sql = editor.getValue().trim();
        runQuery(sql, bucket);

        env.shutdown();
        env=null;

    } catch (Exception e){
        LOGGER.error("Database Connection Error ");

        msgs.setValue(dateFormat.format(new Date())
                + "   Connection Error for  " + hostFld.getValue().trim()
                + "  " + bucketFld.getValue().trim());


        e.printStackTrace();


        bucket.close();
        cluster.disconnect();
        bucket=null;
        cluster=null;


    } finally {
        // close connections
        bucket.close();
        cluster.disconnect();
        bucket=null;
        cluster=null;


    }
    env=null;
    bucket=null;
    cluster=null;
}
#5

I think I solved it I was creating multiple CouchbaseEnvironments each time .

1 Like