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

Cluster calls TrySetResult which might not return for a long time

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.8.0
    • Fix Version/s: 2.8.1
    • Component/s: Connectivity
    • Labels:
      None

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rstam Robert Stam
              Reporter:
              rstam Robert Stam
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: