No issues with this code until recently. The relevant changes were (1) updated SDK from 3.0.0 to 3.0.1 and (2) changed from serial calls to GetAsync to parallel async tasks calling GetAsync.
Note also, this is extremely low volume in this case, passing less than than 100 keys at time, usually 25 or less. The error (from logs) along with its inner exception is shown below followed by a code sample for how it is being called.
Why/when does this exception occur and what is the best way to mitigate/recover within the app code?
ERROR - GetAsync failed for document key "Cache_Service_DocType_52.454_-1.748_51.5268474_-0.4614485" with exeption: Cannot access a disposed object.
Object name: 'DataFlowConnectionPool'.
ErrorMsg: System.AggregateException: One or more errors occurred. (Value cannot be null. (Parameter 'endPoint'))
System.ArgumentNullException: Value cannot be null. (Parameter 'endPoint')
at Couchbase.CouchbaseBucket.SendAsync(IOperation op, CancellationToken token, Nullable`1 timeout)
at Couchbase.Core.Retry.RetryOrchestrator.RetryAsync(BucketBase bucket, IOperation operation, CancellationToken token, Nullable`1 timeout)
at Couchbase.KeyValue.CouchbaseCollection.ExecuteLookupIn(String id, IEnumerable`1 specs, LookupInOptions options)
at Couchbase.KeyValue.CouchbaseCollection.GetAsync(String id, GetOptions options)
Code:
var getCachedDocsTasks = docKeys.Select(async key =>
{
cachedDoc = await _cacheService.GetAsync<CacheDocInfo>(key);
listOfCachedDocsResult.Add(cachedDoc);
});
await Task.WhenAll(getCachedDocsTasks);
public class CacheService : ICacheService
{
public async Task<T> GetAsync<T>(string key)
{
try
{
var getAsyncTask = _collection.GetAsync(key);
var result = await getAsyncTask;
return result != null && result.Cas != 0 ? result.ContentAs<T>() : default(T);
}
catch (Couchbase.Core.Exceptions.KeyValue.DocumentNotFoundException)
{
_logger.LogInformation($"document with Key '{key}' not found");
return default(T);
}
catch (Exception ex)
{
_logger.LogError($"ERROR - GetAsync failed for document key {key} with exeption: {ex.Message}");
throw;
}
}
}