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

Cannot connect to remote server when running on Mono on Windows

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.3
    • Component/s: Connectivity
    • Labels:
      None
    • Environment:
      Windows 7 mono 4.6.2

      Works fine running on Mono 4.6.2 on Ubuntu linux
      Works fine running on .NET Framework on Windows

      Can connect to local server when running on Mono on Windows

      When connecting to a remote server when running Mono on Windows:

      Unhandled Exception:
      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 : "1", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "

      { ClusterId : 1, EndPoint : "Unspecified/ds058508.mlab.com:58508" }

      ", EndPoint: "Unspecified/ds058508.mlab.com:5850
      8", State: "Disconnected", Type: "Unknown" }] }.
      at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException (MongoDB.Driver.Core.Clusters.ServerSelectors.IServerSelector selector, MongoDB.Driver.Core.Clusters.ClusterDescription description) [0x00013] in <0763d4a07cbf42da8f075cc7041f4302>:0
      at MongoDB.Driver.Core.Clusters.Cluster+WaitForDescriptionChangedHelper.HandleCompletedTask (System.Threading.Tasks.Task completedTask) [0x00009] in <0763d4a07cbf42da8f075cc7041f4302>:0
      at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChanged (MongoDB.Driver.Core.Clusters.ServerSelectors.IServerSelector selector, MongoDB.Driver.Core.Clusters.ClusterDescription description, System.Threading.Tasks.Task descriptionChangedTask, System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) [0x00021] in <0763d4a07cbf42da8f075cc7041f4302>:0
      at MongoDB.Driver.Core.Clusters.Cluster.SelectServer (MongoDB.Driver.Core.Clusters.ServerSelectors.IServerSelector selector, System.Threading.CancellationToken cancellationToken) [0x00047] in <0763d4a07cbf42da8f075cc7041f4302>:0
      [ERROR] FATAL UNHANDLED EXCEPTION: 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 : "1", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "

      { ClusterId : 1, EndPoint : "Unspecified/ds058508.mlab.com:58508" }

      ", EndPoint:
      "Unspecified/ds058508.mlab.com:58508", State: "Disconnected", Type: "Unknown" }] }.
      at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException (MongoDB.Driver.Core.Clusters.ServerSelectors.IServerSelector selector, MongoDB.Driver.Core.Clusters.ClusterDescription description) [0x00013] in <0763d4a07cbf42da8f075cc7041f4302>:0
      at MongoDB.Driver.Core.Clusters.Cluster+WaitForDescriptionChangedHelper.HandleCompletedTask (System.Threading.Tasks.Task completedTask) [0x00009] in <0763d4a07cbf42da8f075cc7041f4302>:0
      at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChanged (MongoDB.Driver.Core.Clusters.ServerSelectors.IServerSelector selector, MongoDB.Driver.Core.Clusters.ClusterDescription description, System.Threading.Tasks.Task descriptionChangedTask, System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) [0x00021] in <0763d4a07cbf42da8f075cc7041f4302>:0
      at MongoDB.Driver.Core.Clusters.Cluster.SelectServer (MongoDB.Driver.Core.Clusters.ServerSelectors.IServerSelector selector, System.Threading.CancellationToken cancellationToken) [0x00047] in <0763d4a07cbf42da8f075cc7041f4302>:0

      Example code:

      using System;
      using MongoDB.Bson.Serialization;
      using MongoDB.Bson.Serialization.IdGenerators;
      using MongoDB.Driver;
      using Newtonsoft.Json;

      namespace ConsoleApplication1
      {
      internal class Program
      {
      public static void Main(string[] args)
      {
      var mongourl = "<CONNECTION STRING>";
      var dbName = "<DATABASE NAME>";

      BsonSerializer.RegisterIdGenerator(
      typeof(string),
      StringObjectIdGenerator.Instance
      );

      var clientSettings =
      MongoClientSettings.FromUrl(new MongoUrl(mongourl));

      var mongoClient = new MongoClient(clientSettings);
      var db = mongoClient.GetDatabase(dbName);

      var collection = db.GetCollection<TestClass>("test");
      var test = new TestClass

      {Name = "Test"}

      ;
      collection.InsertOne(test);

      var result = collection.Find(Builders<TestClass>.Filter.Empty).ToList();

      Console.WriteLine(JsonConvert.SerializeObject(result));
      Console.WriteLine("Press any key to continue...");
      Console.ReadKey();
      }
      }

      public class TestClass
      {
      public string Id

      { get; set; }
      public string Name { get; set; }

      }

      }

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            bradleylandis Bradley Landis
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: