When giving out a reference to a cached bucket, the ClusterController was not adding a new reference to the bucket.
However, simply adding a new reference would not be sufficient. Disposing of the bucket is handled by the bucket itself, and while the bucket does call DestroyBucket on its associated ClusterController, thus removing the bucket from the cache, there is no shared locking mechanism. So it is entirely possible that in the ClusterController, between the ContainsKey call and the _buckets[bucketName] call, the bucket could become disposed.
Therefore, AddRef was changed to check the _disposed value and return -1 if the bucket is disposed. It can be used as an atomic add-or-fail operation by the ClusterController. Once the ClusterController finds a bucket in its cache, it will attempt to add the reference before returning the cached bucket. If the add reference fails, it will bootstrap a new bucket.
|For Gerrit Dashboard: NCBC-1149|
|64601,4||NCBC-1149: Correct issue in bucket reference counting||master||couchbase-net-client||Status: MERGED||+2||+1|