Manager::selectServer() should throw when failing to select a server

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Minor - P4
    • 1.1.0
    • Affects Version/s: 1.0.0
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Manager::selectServer() currently constructs a Server object from an empty ID if it fails to select a server. Consider the following code example, where localhost:27017 is a primary in a one-member replica set (i.e. no secondary):

      $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017/?replicaSet=rs");
      
      $rp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY);
      var_dump($manager->selectServer($rp));
      

      This yields:

      object(MongoDB\Driver\Server)#3 (0) {
      }
      PHP Fatal error:  Uncaught exception 'MongoDB\Driver\Exception\RuntimeException' with message 'Failed to get server description, server likely gone'
      

      Curiously, an empty object is dumped even though RuntimeException is thrown (presumably from within the debug handler). It would be preferable if we threw this exception upon creating the Server object internally.

            Assignee:
            Hannes Magnusson (Inactive)
            Reporter:
            Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: