Bug: disposing of a bucket causes issues

Hi.
Using .NET SDK 2.5.8.0
Couchbase 5.0.1 Community

When calling bucket.dispose() all future requests to my url return an error .
“users” is a Couchbase type bucket
ClusterHelper is defined in global.asax

IBucket bucket = ClusterHelper.GetBucket("users");

IDocumentResult result = bucket.GetDocument<dynamic>("test");

bucket.dispose();

Some indexer is going crazy in my logs
couchbase.zip (5.2 KB)

Maybe I don’t understand the question, but why are you disposing after you make one operation?
You do a dispose when you want to disconnect the SDK from the bucket/cluster.
See https://docs.couchbase.com/dotnet-sdk/2.7/managing-connections.html#disconnecting-from-a-bucket
Since you mentioned “global.asax” … possibly a good place to call dispose would be on the “application_end” event … not after an operation.

I do a “dispose” for the same reason why I dispose a database recordset once I don’t need it anymore on the page.
Then on the next run, i just get the data again into the recordset object.

Couchbase doesn’t work like that?

But regardless, in the link you provided, under bucket.dispose() it says:

This will release only the resources allocated for this bucket and it is possible to reopen it at a later point.

Performing a “GetBucket” after disposing it did not work in my case.

@alon.schachter - there is no benefit to creating and disposing a bucket per operation; the cost of recreating the connections, authenticating, server negoiation is high. The SDK itself handles managing and pooling connections as long as an instance is available from application startup and closed when the app shuts down.

That being said, performing a GetBucket after disposing of it should work, I’ll see if i can recreate. Also, v2.5.8 is fairly old, you may want to update to the newest version.

-Jeff

1 Like

@alon.schachter -

I couldn’t replicate using the following code:

       var cluster = new Cluster(new ClientConfiguration
        {
            Servers = new List<Uri>
            {
                new Uri("http://localhost:8091")
            }
        });
        cluster.Authenticate("Administrator", "password");

        for (var i = 0; i < 1000; i++) {
            var bucket = cluster.OpenBucket("default");
            var insert = bucket.Upsert<dynamic>("foo", "bar" +i);
            bucket.Dispose();
        }

Running this gives me “bar999” when it finishes - opening and Disposing the bucket 1000x’s.

Note that a “Bucket” isn’t an individual recordset, its the actual database resource on the server.

-Jeff

@jmorris

Thanks Jeff,
I won’t dispose of buckets.

I was able to reproduce this issue also on the 2.7.6 SDK
I’m attaching a asp.net solution just in case you still wanna solve it.
This SDK version gives me a more elaborate error message then just “operations timed out” like in 2.5.8

The node 127.0.0.1:11210 that the key was mapped to is either down or unreachable. The SDK will continue to try to connect every 1000ms. Until it can connect every operation routed to it will fail with this exception.

Edit the web.config first, then run test.aspx and then refresh the page.
Use Couchbase 5.0.1 Community. and create a Couchbase type bucket.

If you still can’t repro, just let it go…

@alon.schachter - thanks, I’ll look into the issue you encountered. :+1:

What does the cluster setup look like? I am assuming your not failing over or doing a swap/rebalance?

Thanks
Jeff

1 Like

@jmorris
No… just one node
on my local machine. the same one i’m running my code on
Windows 10

@alon.schachter -

The issue is that your using the ClusterHelper which is managing the IBucket reference, but your explicitly Disposing the reference - the ClusterHelper is holding onto the disposed reference. You just need to use ClusterHelper.RemoveBucket("users_Couchbase"); instead of bucket.Dispose(); and it should work as expected.

-Jeff

1 Like