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

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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical - P2 Critical - P2
    • 1.8.2
    • 1.8.1
    • None
    • None
    • Fully Compatible

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: