C# Asp.net MVC 4,7,2 - bucket.DefaultCollectionAsync not stopping!

I am simply trying to read my Bucket but it goes into infinite loop. The process never ends.

c# Asp.net 4,7,2

var collection = bucket.DefaultCollectionAsync().GetAwaiter().GetResult();


var cluster = Cluster.ConnectAsync("couchbase://localhost", "user", "pass").GetAwaiter().GetResult();
var bucket = cluster.BucketAsync("MyBucket").GetAwaiter().GetResult();
 var collection = bucket.DefaultCollectionAsync().GetAwaiter().GetResult();

It seems possible that there might be a deadlocking issue. Is there a reason that you can’t use the await syntax instead? E.g. var collection = await bucket.DefaultCollectionAsync()

Hi Matthew,

Thank you for the answer. But I use not async method. Since my method is asynchronous, I use “GetAwaiter”. Do you need to use asynchronous method?

Generally speaking, calling GetAwaiter().GetResult() is an anti-pattern that should only be used if absolutely necessary. It is known to cause problems with thread pool depletion and deadlocks, such as you seem to be encountering.

I’d strongly recommend moving to asynchronous code as the best solution. However, if that isn’t possible, there is this workaround. However, it incurs a performance penalty.

Hi btburnett3,

Thank you for your answer. I think I’ll use the asynchronous method.

Thank you to everyone.

1 Like