Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2564

Cluster calls TrySetResult which might not return for a long time

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.8.1
    • Affects Version/s: 2.8.0
    • Component/s: Connectivity
    • None

      UpdateClusterDescription in Cluster.cs calls TrySetResult on a TaskCompletionSource.

      There is an issue with how TrySetResult works. If there are already other tasks waiting for this result they will execute synchronously in the current thread which means that TrySetResult might not return for a long time depending on how many tasks start to run as a result. We require that TrySetResult return immediately so that we can continue and finish the process of updating the cluster state.

      In .NET Framework 4.6.1 we could use the RunContinuationsAsynchronously TaskCreationOptions to specify that TrySetResult should only schedule waiting tasks for asynchronous execution and not run them synchronously, so that TrySetResult returns as quickly as possible.

      Since we currently only require .NET Framework 4.5.2 a work around would be:

      Task.Run(() => oldDescriptionChangedTaskCompletionSource.TrySetResult(true));
      

      so that TrySetResult itself is called asynchronously from a new Task.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: