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

MongoServer.Primary is not thread-safe when using a replicaset

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 1.8.2
    • Affects Version/s: 1.8.1
    • Component/s: None
    • None
    • Fully Compatible

      System.InvalidOperationException: Sequence contains more than one matching element
      at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
      at MongoDB.Driver.MongoServer.get_Primary()

      MongoServerInstance.Primary is calling _serverProxy.Instances.SingleOrDefault(x => x.IsPrimary);

      In our case proxy is ReplicaSetMongoServerProxy

      When method ProcessConnectedInstanceStateChange is called, the previously disconnected instance can come with Primary set to true.
      In this case the previous Primary instance may not see its flag unset by ProcessConnectedPrimaryStateChange method before a call to MongoServerInstance.Primary is done => Exception.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            arnaud.tamaillon Arnaud TAMAILLON
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: