Description
When giving out a reference to a cached bucket, the ClusterController was not adding a new reference to the bucket.
https://github.com/couchbase/couchbase-net-client/pull/58
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.