Troubleshoot Couchbase .net sdk 3.2 connection issues

@Anbu_J

I can think of a couple of possible problems that may cause this.

The first is some kind of race condition, possibly within the SDK itself, and the different startup procedures of the console vs ASP.Net applications is triggering it. You might try adding await cluster.WaitForReadyAsync() before calling to get the Bucket to see if that makes a difference.

The second thought I had was the SynchronizationContext. Legacy ASP.Net runs with a specific synchronization context that only lets one Task completion run at a time per HTTP request. A console app would run in SynchronizationContext.Default, which is unrestricted. This could be causing some kind of deadlock or other issue.

The SDK itself should be immune to this, unless there is a bug. Or it could be something within your startup logic leading up to InitializeCouchbase. A few things to try:

  1. Make sure you’re not using .Wait() or .Result on a task, especially in your action methods. This is almost guaranteed to cause a deadlock.
  2. Try adding .ConfigureAwait(false) on all your awaits within InitializeCouchbase
  3. If that doesn’t work, try adding await Task.Delay(100).ConfigureAwait(false) to the top of InitializeCouchbase as an experiment (this should force the rest of the method off the synchronization context).

Note: #3 I wouldn’t leave in for production, that’s just for diagnosis. The others are fine for production.

1 Like