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

Client does not recover automatically from certain failures

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.8
    • Affects Version/s: 1.6.1
    • Component/s: None
    • Labels:
    • Environment:
      The client is a Windows Service using .NET 4.0 and running on Windows Server 2003 R2

      We have a mongodb replica set with 1 master and 2 slaves. All slaves can be become masters.

      At one point the client, a Windows Service using .NET 4.0, stopped working. When I checked the logs, there was a large number of these exceptions:

      MongoDB.Driver.MongoConnectionException: Unable to connect to a member of the replica set matching the read preference Primary\r\n at MongoDB.Driver.Internal.MultipleInstanceMongoServerProxy.ThrowConnectionException(ReadPreference readPreference) in c:\\projects\\mongo-csharp-driver\\Driver\\Internal
      MultipleInstanceMongoServerProxy.cs:line 509\r\n at MongoDB.Driver.Internal.MultipleInstanceMongoServerProxy.Connect(TimeSpan timeout, ReadPreference readPreference) in c:\\projects\\mongo-csharp-driver\\Driver\\Internal
      MultipleInstanceMongoServerProxy.cs:line 224\r\n at MongoDB.Driver.Internal.MultipleInstanceMongoServerProxy.ChooseServerInstance(ReadPreference readPreference) in c:\\projects\\mongo-csharp-driver\\Driver\\Internal
      MultipleInstanceMongoServerProxy.cs:line 168\r\n at MongoDB.Driver.Internal.DiscoveringMongoServerProxy.ChooseServerInstance(ReadPreference readPreference) in c:\\projects\\mongo-csharp-driver\\Driver\\Internal
      DiscoveringMongoServerProxy.cs:line 126\r\n at MongoDB.Driver.MongoServer.AcquireConnection(MongoDatabase database, ReadPreference readPreference) in c:\\projects\\mongo-csharp-driver\\Driver\\Core
      MongoServer.cs:line 1051\r\n at MongoDB.Driver.MongoCursorEnumerator`1.AcquireConnection() in c:\\projects\\mongo-csharp-driver\\Driver\\Core
      MongoCursorEnumerator.cs:line 299\r\n at MongoDB.Driver.MongoCursorEnumerator`1.GetFirst() in c:\\projects\\mongo-csharp-driver\\Driver\\Core
      MongoCursorEnumerator.cs:line 312\r\n at MongoDB.Driver.MongoCursorEnumerator`1.MoveNext() in c:\\projects\\mongo-csharp-driver\\Driver\\Core
      MongoCursorEnumerator.cs:line 230\r\n at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)\r\n at MongoDB.Driver.MongoCollection.FindOneAs[TDocument](IMongoQuery query) in c:\\projects\\mongo-csharp-driver\\Driver\\Core
      MongoCollection.cs:line 570\r\n at MongoDB.Driver.MongoCollection.RunCommandAs(Type commandResultType, IMongoCommand command) in c:\\projects\\mongo-csharp-driver\\Driver\\Core
      MongoCollection.cs:line 1658\r\n at MongoDB.Driver.MongoCollection.RunCommandAs(Type commandResultType, IMongoCommand command) in c:\\projects\\mongo-csharp-driver\\Driver\\Core
      MongoCollection.cs:line 1680\r\n at MongoDB.Driver.MongoCollection.RunCommandAs[TCommandResult](IMongoCommand command) in c:\\projects\\mongo-csharp-driver\\Driver\\Core
      MongoCollection.cs:line 1650\r\n at MongoDB.Driver.MongoCollection.FindAndModify(IMongoQuery query, IMongoSortBy sortBy, IMongoUpdate update, IMongoFields fields, Boolean returnNew, Boolean upsert) in c:\\projects\\mongo-csharp-driver\\Driver\\Core
      MongoCollection.cs:line 461\r\n at MongoDB.Driver.MongoCollection.FindAndModify(IMongoQuery query, IMongoSortBy sortBy, IMongoUpdate update, Boolean returnNew, Boolean upsert) in c:\\projects\\mongo-csharp-driver\\Driver\\Core
      MongoCollection.cs:line 440\r\n at MongoDB.Driver.MongoCollection.FindAndModify(IMongoQuery query, IMongoSortBy sortBy, IMongoUpdate update, Boolean returnNew) in c:\\projects\\mongo-csharp-driver\\Driver\\Core
      MongoCollection.cs:line 421\r\n at MongoDB.Driver.MongoCollection.FindAndModify(IMongoQuery query, IMongoSortBy sortBy, IMongoUpdate update) in c:\\projects\\mongo-csharp-driver\\Driver\\Core
      MongoCollection.cs:line 404\r\n
      ...
      (Note that the actual read preference of the collection is ReadPreferenceMode.Secondary, but that has not caused any problems with FindAndModify until now)

      We were not able to see anything wrong with the replica set itself, so we simply restarted the client. The exceptions immediately went away and the client continued to work perfectly fine after that.

      I cannot determine what caused the client to begin throwing those exceptions. It might have been some temporary network failure. The real problem is that the driver was not able to recover from that failure by itself. I would expect the driver to be more robust and to be able to resume normal operation without the need for a restart.

      Is there a code workaround for this issue? Would it help if we set the Read preference mode to SecodaryPreferred or to Primary?

        1. mongo01.txt
          86 kB
        2. mongo02.txt
          89 kB
        3. mongo03.txt
          91 kB
        4. Ping.aspx
          0.5 kB
        5. primary.txt
          387 kB

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            kalin.gyokov Kalin Gyokov
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: