ObjectDisposedException on ASP.NET Core

We have a very simple asp.net core application reading data from a test Couchbase server. Frequently we get exceptions when executing our queries.(stack shown below). We use latest CouchbaseNetClient 2.7.7

There are no error logs on the server. We simply follow the example given by the documentation without anything fancy.
void Open()
{
var cfg = new ClientConfiguration
{
Servers = new List { new Uri(dbpath) }
};
ClusterHelper.Initialize(cfg);
// provide authentication to cluster
ClusterHelper.Get().Authenticate(new PasswordAuthenticator(user, pwd));
_bucket = ClusterHelper.GetBucket(dbName);
EnsureIndexes(dbName);
}

List Query(stmt)
{
_bucket.Query(stmt)…
}

ERROR System.ObjectDisposedException: The collection has been disposed.
Object name: ‘BlockingCollection’.
at System.Collections.Concurrent.BlockingCollection1.CheckDisposed() at System.Collections.Concurrent.BlockingCollection1.TryAddWithNoTimeValidation(T item, Int32 millisecondsTimeout, CancellationToken cancellationToken)
at Couchbase.Tracing.ThresholdLoggingTracer.ReportSpan(Span span) in C:\Jenkins\workspace\dotnet\couchbase-net-client-scripted-build-pipeline\couchbase-net-client\Src\Couchbase\Tracing\ThresholdLoggingTracer.cs:line 115
at OpenTracing.Util.AsyncLocalScope.Dispose() in C:\projects\opentracing-csharp\src\OpenTracing\Util\AsyncLocalScope.cs:line 40
at Couchbase.Core.Buckets.CouchbaseRequestExecuter.SendWithRetry[T](IQueryRequest queryRequest) in C:\Jenkins\workspace\dotnet\couchbase-net-client-scripted-build-pipeline\couchbase-net-client\Src\Couchbase\Core\Buckets\CouchbaseRequestExecuter.cs:line 1026

Just to provide more information, I created 1 bucket and inject it into asp.net controllers. So all controllers are sharing the same bucket (from different threads). Is that the problem? What would be the right way to avoid it?
Any input is appreciated.

@wangsha -

It looks like that for some reason the ThreshholdLoggingTracer was Disposed. This could happen if the Cluster object is disposed since it owns the reference to it. Is it possible another thread could be closing or disposing of the cluster? An app pool refresh or restart of the hosting server could trigger this since undoubtedly there will be other threads possibly handling requests.

That should be fine as long as the Cluster and Bucket objects are created during application startup and disposed/closed during application shutdown.

Try reading these docs:

-Jeff

Jeff, thanks for the quick reply,
In my code, I used ClusterHelper to manage my cluster. To further investigate the issue, I changed it to keep an instance of Cluster inside my database service that is injected in MVC.

            _cluster = new Cluster(config);
            var credentials = new PasswordAuthenticator(user, pwd);
            _cluster.Authenticate(credentials);                
            _bucket = _cluster.OpenBucket(dbName);

Somehow this seems to solve the issue!
Does this make sense? Maybe the ClusterHelper secretly dispose the cluster somewhere?