Problem Connecting to server when client is started before server


#1

I’m having an issue with the java 2.1.0 api. If I create a connection and do a get a request when the couchbase is down I am getting a null pointer exception on any get(lookupKey) after bringing the couchbase backup. It happens when the couchbase is down, the connection is set up and the get(lookupKey) has timed out. After that bringing the couchbase up, even though it shows the message for connecting to the host and bucket, the get(lookupKey) still throws a null pointer. However if the couchbase was initially up the problem doesn’t happen. I can bring the server down run a get request bring it up and the next request will succeed.

–Initial connection
java.net.ConnectException: Connection refused: no further information: localhost/127.0.0.1:11210
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:712)
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)
[null][KeyValueEndpoint]: Could not connect to endpoint, retrying with delay 4096 MILLISECONDS:

–Request Timeout

04 Feb 2015 23:06:51,225 ERROR (ConnectionManager.java:85) java.util.concurrent.TimeoutException
java.lang.RuntimeException: java.util.concurrent.TimeoutException
at com.couchbase.client.java.util.Blocking.blockForSingle(Blocking.java:93) ~[java-client-2.1.0.jar:2.1.0]
at com.couchbase.client.java.CouchbaseCluster.openBucket(CouchbaseCluster.java:108) ~[java-client-2.1.0.jar:2.1.0]
at com.couchbase.client.java.CouchbaseCluster.openBucket(CouchbaseCluster.java:94) ~[java-client-2.1.0.jar:2.1.0]

–After bringing couchbase back up

Connected to Node localhost
Opened bucket erp

–Null pointer exception on client.getBucket().get(lookupKey)

java.lang.NullPointerException


#2

@dcore

ah I see whats going on here.

The problem is that your initial openBucket() request fails if you only have a node cluster and this server is down. This is because since the client cannot establish an initial connection it has no clue how your cluster looks like and so forth. This is why for a production case we recommend passing in more than 1 server so in case one is down we can successfully connect nevertheless.

So if your openBucket attempt fails you need to back off and either try again or fail. I guess the NPE is happening because your “Bucket” reference never gets set in your code since the openBucket operation fails?