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

Driver ignores timeout option when machine is not accessible

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Critical - P2 Critical - P2
    • None
    • 1.9.1
    • Connectivity

    Description

      When we set a timeout option it is ignored if the machine is turned off or not accessible. We use MongoDB for caching and have some fallback logic in case the DB is not accessible, but in this case the driver ignores the timeout value and needs at least 20 seconds to throw an exception.

      Here is a sample code. We used the IP of a turned off machine for the second test, you may also try with a non-existing machine:

      I've also attached the .cs file we used to demonstrate the issue.

       static void Main(string[] args)
              {
                  var stopwatch = new Stopwatch();
       
                  stopwatch.Start();
       
                  var settings = new MongoClientSettings
                  {
                      Server = new MongoServerAddress("localhost", 27017),
                      ConnectTimeout = TimeSpan.FromSeconds(2),
                  };
       
                  var client = new MongoClient(settings);
                  try
                  {
                      client.GetServer().Connect();
                  }
                  catch (Exception e)
                  {
                      Console.WriteLine(e);
                  }
                 
       
                  stopwatch.Stop();
                  Console.WriteLine(stopwatch.Elapsed);
       
                  
                  // Non-existing machine
                  stopwatch.Reset();
                  stopwatch.Start();
       
                  settings = new MongoClientSettings
                  {
                      Server = new MongoServerAddress("XXX.XXX.XXX.XX", 27017),
                      ConnectTimeout = TimeSpan.FromSeconds(2),
                  };
       
                  client = new MongoClient(settings);
                  try
                  {
                      client.GetServer().Connect();
                  }
                  catch (Exception e)
                  {
                      Console.WriteLine(e);
                  }
       
                  stopwatch.Stop();
                  Console.WriteLine(stopwatch.Elapsed);
              }

      Attachments

        Activity

          People

            Unassigned Unassigned
            Stanislav.vr Stanislav Radkov [X]
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: