We discovered a bug with the .Net SDK similar to the following Post;
Steps to reproduce (this is in a single instance of the application):
-
Using .NetCoreApp 1.1 (Using native dependency injection)
-
Adding a Singleton to IServiceCollection of ICluster (with necessary configuration)
-
Adding a Singleton to IServiceCollection of IBucket (with necessary configuration)
-
Calling IBucket.Upsert() throws the following exception:
{System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary2.get_Item(TKey key) at Couchbase.Core.Buckets.CouchbaseRequestExecuter.<SendWithRetryAsync>d__15
1.MoveNext()} -
Stop the service and restart the service
-
The same Upsert() with the same document then succeeds
The workaround we came up with is to create and dispose of a Bucket instance immediately:
//our CreateBucketInstance has these two relevant lines of code
var manager = cluster.CreateManager(configuration.ManagementUser, configuration.ManagementPassword);
var createResult = manager.CreateBucket(configuration.BucketName, configuration.BucketSize, saslPassword: configuration.BucketPassword, threadNumber: ThreadNumber.Three, flushEnabled: configuration.FlushEnabled);
using (var newBucket = CreateBucketInstance(configuration, cluster)) { }
In a separate step, a new instance of the Bucket object is instantiated - which is then used to perform the Upsert() and succeeds.
Ideally when a bucket is created it should be able to be used immediately.