Writing to the wrong server

I am using couchbase 4.5.1-2845 (commuinty edition) with NetClient 2.4.7.
This is how I initialise the cluster:

List servers = new List();
servers.Add(new Uri(“http://cb-ip-1:8091/pools/default”));
JsonSerializerSettings serializerSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All };
ClientConfiguration config = new ClientConfiguration
Servers = servers,
Serializer = () => new DefaultSerializer(serializerSettings, serializerSettings),
PoolConfiguration = new PoolConfiguration
MaxSize = 10,
MinSize = 5,
SendTimeout = 12000
ConnectionPoolCreator = ConnectionPoolFactory.GetFactory<SharedConnectionPool>()
cluster = new Cluster(config);
bucket = cluster.OpenBucket(“my-bucket”);

The server where I installed the app, had Couchbase installed on it, the documents were written to the localhost instance instead of the specified http://cb-ip-1:8091 instance. Once I stopped the local couchbase instance, it started writing to the correct instance.
How can I be sure it writes to the correct instance?
This also happened when I tried to debug the problem, the data was being written to my local instance instead of the one I specified.


After the line:
cluster = new Cluster(config);
cluster.Configuration.Servers contains only the specified server.
After the line:
bucket = cluster.OpenBucket(“my-bucket”);
cluster.Configuration.Servers contains both localhost and http://cb-ip-1:8091


I’ve tried to reproduce this behavior on my machine, using both SDK 2.4.7 and 2.5.8, but I haven’t reproduced it yet. Specifically, I’ve copied your code and then stepped through with the debugger, but cluster.Configuration.Servers still contains just the one URL.

A few things you might try (educated guesses only):

  • Try adding “my-bucket” to config.Buckets before new Cluster(config)
  • Try upgrading to the latest SDK, in case it’s been incidentally fixed
  • Try changing the URL to just http://cb-ip-1:8091/ without the path, that’s all that’s needed.

@gilad.teller -

This could happen is if you have a hosts file entry mapping http://cb-ip-1:8091 to localhost. You can enable logging as well to see which server the client is bootstrapping to as well; that may help to determine was is going on here.

Only upgrading the SDK version solved the problem.

  • Adding BucketConfigs to the ClientConfiguration and changing the URL as suggested didn’t help.
  • Also, I made sure there there is no mapping from cb-ip-1 to localhost.
1 Like