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

Uncought task exception when connection timeout occurs

      After creating a MongoClient and getting the Database with
      var client = new MongoClient(location);
      database = client.GetDatabase(databaseName);
      the client automatically tries to connect to the server of the location string. If the server is present everything works fine, but if the connection can not be established an uncaught task exception is raised:
      "System.AggregateException: Ausnahmen einer Aufgabe wurden nicht überwacht (entweder wegen Wartens auf die Aufgabe oder wegen des Zugriffs auf die Ausnahmeeigenschaft. Daher wurde die nicht überwachte Ausnahme vom Finalizer-Thread erneut ausgelöst. ---> System.TimeoutException: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{ ReadPreference =

      { Mode = Primary, TagSets = System.Collections.Generic.List`1[MongoDB.Driver.TagSet] }

      }, LatencyLimitingServerSelector

      { AllowedLatencyRange = 00:00:00.0150000 }

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

      { ClusterId : 1, EndPoint : "Unspecified/localhost:27017" }

      ", EndPoint: "Unspecified/localhost:27017", State: "Disconnected", Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.Net.Sockets.SocketException: Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte 127.0.0.1:27017 ..."
      and catched by our UnobservedTaskExceptionEventHandler (
      TaskScheduler.UnobservedTaskException += UnobservedTaskExceptionEventHandler.
      Since we do not want to continue work after unobserved task exception in our system, the normal behaviour is to shut down and restart the application.
      Is there a way to avoid the exception? Since the Task can not be reached from outside the driver, we do not see a way to catch it before the task gets out of reach and the exception is handed to the handler by the garbagecollector.
      As a workaround we modified the Handler to not restart on TimeoutExceptions, but we would appreciate a different solution.

            Assignee:
            Unassigned Unassigned
            Reporter:
            PHebing Philipp Hebing
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: