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

SynchronizationContext.Current bleed

      1. In one independent thread, context, uses a AsyncHelper.RunSync(...) wrapper invoke mongodb's UpdateOneAsync method.
      What "AsyncHelper" does is it replaces the SynchronizationContext.Current with a "ExclusiveSynchronizationContext", and replace back, one finished execution.

      2. In another completely independent thread/context, executing following code:
      code line 1...
      ... // SynchronizationContext.Current is null
      await mongodb.UpdateOneAsync(); //with, or without .ConfigureAwait(false)
      ...// SynchronizationContext.Current is "ExclusiveSynchronizationContext"

      These 2 calls not related to each other.

      This is not 100% time happening. But when happen, it causes deadlock, or potential security issue as it leaks SynchronizationContext.

      The code of AsyncHelper is attached.

        1. AsyncHelper.cs
          5 kB
          Steven [X]

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            StevenXi Steven [X]
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: