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

Inconsistent MongoClient Connection Behavior- Timeout depending upon connection setup

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.4
    • Component/s: Connectivity
    • Labels:
      None
    • Environment:
      .Net Full, Windows Server 2012

      So I have a long running Windows Service that is performing a few dozen tasks each of which read/write to two different mongo servers (one being a 3 member replica set and the other being a single member replica set).

      The MongoClients for all processes are being handled by a Singleton. This has been up and running for a year+ with no issues using the following code to acquire a MongoClient.

      ```
      _client = new MongoClient(connstring);
      ```
      Simple Enough.
      Now we wanted to try and get some analytics for the queries and changed it to the following;

      ```
      Action<string, DateTime, TimeSpan, bool> _trackIt = null;
      var mongoUrl = new MongoUrl(connstring);
      var mongoClientSettings = MongoClientSettings.FromUrl(mongoUrl);
      mongoClientSettings.ClusterConfigurator = clusterConfigurator =>
      {
      if (_trackIt != null)

      { //Code Here for profiling that is never called }

      };

      _client = new MongoClient(mongoClientSettings);
      ```

      Now with the Example above the Action used for tracking is in fact null as this process isn't collecting any analytics on performance.
      I would expect this to perform the same but after a couple of hours of running the tasks without an issue we start getting the following error and have to constantly re-start the service.

      ```
      System.TimeoutException: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = WritableServerSelector, LatencyLimitingServerSelector

      { AllowedLatencyRange = 00:00:00.0150000 }

      }. Client view of cluster state is { ClusterId : "8536", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "

      { ClusterId : 8536, EndPoint : "Unspecified/someserver.in.datacenter.com:27017" }

      ", EndPoint: "Unspecified/someserver.in.datacenter.com:27017", State: "Disconnected", Type: "Unknown" }] }.
      at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException(IServerSelector selector, ClusterDescription description)
      at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChangedHelper.HandleCompletedTask(Task completedTask)
      at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChanged(IServerSelector selector, ClusterDescription description, Task descriptionChangedTask, TimeSpan timeout, CancellationToken cancellationToken)
      at MongoDB.Driver.Core.Clusters.Cluster.SelectServer(IServerSelector selector, CancellationToken cancellationToken)
      at MongoDB.Driver.Core.Bindings.WritableServerBinding.GetWriteChannelSource(CancellationToken cancellationToken)
      at MongoDB.Driver.Core.Operations.FindAndModifyOperationBase`1.Execute(IWriteBinding binding, CancellationToken cancellationToken)
      at MongoDB.Driver.OperationExecutor.ExecuteWriteOperation[TResult](IWriteBinding binding, IWriteOperation`1 operation, CancellationToken cancellationToken)
      at MongoDB.Driver.MongoCollectionImpl`1.ExecuteWriteOperation[TResult](IWriteOperation`1 operation, CancellationToken cancellationToken)
      at MongoDB.Driver.MongoCollectionImpl`1.FindOneAndUpdate[TProjection](FilterDefinition`1 filter, UpdateDefinition`1 update, FindOneAndUpdateOptions`2 options, CancellationToken cancellationToken)
      ```

      We get the error for both servers each erroring out independently. No changes are made to the connection string between the failing and error-less execution path.

            Assignee:
            Unassigned Unassigned
            Reporter:
            bret@cityspark.com Bret Ferrier
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: