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

MongoClient constructor throws exception Value is not greater than zero. Parameter name: maxLifeTime

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.11.4
    • Component/s: Connectivity
    • Labels:
      None
    • Environment:
      Raspberry Pi 4. Ubuntu 20.04 64-bit

      I have been using C# MongoDB.Driver 2.6.1 very successfully with MongoDB engine v4.2.10 running on a Raspberry Pi 4 (Ubuntu 20.04 64-bit)

      However when I upgrade MongoDB.Driver to version 2.11.4, an exception is thrown when constructing a MongoClient.

      Here is a simplified version of my GetMongoClient code:

      public static MongoClient GetMongoClient(
       string machineName, 
       string dbName, 
       string username, 
       SecureString password
       )
      {
       var connString = $"mongodb://{machineName}/";
       var settings = MongoClientSettings.FromConnectionString(connString);
      if (!String.IsNullOrEmpty(username) && password != null)
       {
       var credential = MongoCredential.CreateCredential(dbName, username, password);
       settings.Credential = credential;
       }
       
       Console.WriteLine($"GetMongoClient - created settings: {settings}");
       Console.WriteLine($" ConnString: {connString}");
       Console.WriteLine($" HeartbeatTimeout: {settings.HeartbeatTimeout}");
       Console.WriteLine($" MaxConnectionIdleTime: {settings.MaxConnectionIdleTime}");
       Console.WriteLine($" MaxConnectionLifeTime: {settings.MaxConnectionLifeTime}");
       Console.WriteLine($" ServerSelectionTimeout: {settings.ServerSelectionTimeout}");
       Console.WriteLine($" SocketTimeout: {settings.SocketTimeout}");
       Console.WriteLine($" WaitQueueTimeout: {settings.WaitQueueTimeout}");
      return new MongoClient(settings); // <----- EXCEPTION THROWN HERE
      }
      

      Here is the debugging output produced before the exception is thrown:

      GetMongoClient - created settings: ConnectionMode=Automatic;ConnectTimeout=00:00:30;Credentials={{}};GuidRepresentation=CSharpLegacy;HeartbeatInterval=00:00:10;HeartbeatTimeout=-00:00:00.0010000;IPv6=False;MaxConnectionIdleTime=00:10:00;MaxConnectionLifeTime=00:30:00;MaxConnectionPoolSize=100;MinConnectionPoolSize=0;ReadConcern={ };ReadPreference={ Mode : Primary };ReplicaSetName=;RetryReads=TrueRetryWrites=TrueLocalThreshold=00:00:00.0150000;Servers=127.0.0.1:27017;ServerSelectionTimeout=00:00:30;SocketTimeout=00:00:00;SslSettings={CheckCertificateRevocation=False,EnabledProtocols=Tls, Tls11, Tls12};Tls=False;TlsInsecure=False;WaitQueueSize=500;WaitQueueTimeout=00:02:00WriteConcern={ };
       ConnString: mongodb://127.0.0.1/
       HeartbeatTimeout: -00:00:00.0010000
       MaxConnectionIdleTime: 00:10:00
       MaxConnectionLifeTime: 00:30:00
       ServerSelectionTimeout: 00:00:30
       SocketTimeout: 00:00:00
       WaitQueueTimeout: 00:02:00

      And here are the exception details:

      ArgumentOutOfRangeException: Value is not greater than zero: 00:00:00.
      Parameter name: maxLifeTime
       at MongoDB.Driver.Core.Misc.Ensure.IsGreaterThanZero(TimeSpan value, String paramName)
       at MongoDB.Driver.Core.Configuration.ConnectionSettings..ctor(Optional`1 authenticatorFactories, Optional`1 compressors, Optional`1 maxIdleTime, Optional`1 maxLifeTime, Optional`1 applicationName)
       at MongoDB.Driver.Core.Configuration.ConnectionSettings.With(Optional`1 authenticatorFactories, Optional`1 compressors, Optional`1 maxIdleTime, Optional`1 maxLifeTime, Optional`1 applicationName)
       at MongoDB.Driver.ClusterRegistry.ConfigureConnection(ConnectionSettings settings, ClusterKey clusterKey)
       at MongoDB.Driver.Core.Configuration.ClusterBuilder.ConfigureConnection(Func`2 configurator)
       at MongoDB.Driver.ClusterRegistry.CreateCluster(ClusterKey clusterKey)
       at MongoDB.Driver.ClusterRegistry.GetOrCreateCluster(ClusterKey clusterKey)
       at MongoDB.Driver.MongoClient..ctor(MongoClientSettings settings)
       at MyNamespace.GetMongoClient(String machineName, String dbName, String username, SecureString password)
       ...

      As far as I can see the 'maxLifeTime' parameter referred to corresponds to the MongoClientSettings.MaxConnectionLifeTime property, which as you can see from my logging is set to 30 minutes.
      I have also experimented with explicitly settings various other time-related properties, but none have made any difference.

      This only seems to be a problem when running on Linux, as the same code works perfectly using the upgraded driver on Windows.

       

       

            Assignee:
            james.kovacs@mongodb.com James Kovacs
            Reporter:
            ted.francis@zonal.co.uk Ted Francis
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: