title: MongoDB automatic failover not working for second time
body: <p>I am using MongoDB <code>compile "org.grails.plugins:mongodb:3.0.1"</code>. Currently, the automatic failover is working only for first time when i kill MongoDB primary instance. In this case, the secondary becomes Primary and the application is able to read the data. But when i kill again the newly elected Primary and the previously killed is UP now. It means again i have one Primary. The second time failover is not working through MongoDB driver in this case. It throws the <code>MongoServerSelectionException</code>. It's been more than 5 days i am not able to find the solution. Below is my java code</p>
  
  <pre><code>static{
              FileInputStream fis=null;
  
          try {
              /**** Get database ****/
              // if database doesn't exists, MongoDB will create it for you
              fis=new FileInputStream(GRMConstants.MONGODB_PROPERTY_FILE);
              properties=new Properties();
              properties.load(fis);
  
              String[] host=properties.getProperty("MONGODB_SERVER_ADDRESS").split(",");
              List&lt;ServerAddress&gt; server= new ArrayList&lt;ServerAddress&gt;();
              for(int i=0;i&lt;host.length;i++){
              server.add(new ServerAddress(host[i],Integer.valueOf(properties.getProperty("MONGODB_PORT"))));
              }
  
              mongo = new MongoClient(server);
              databaseName=properties.getProperty("MONGO_DATABASE");
              //get database
              database=mongo.getDB(databaseName);     
          } catch (UnknownHostException ex) {
              log.error("UnknownHostException in MongoDBUtil while initilizing MongoDb server ...",ex);
          } catch (MongoException ex) {
              log.error("MongoException in MongoDBUtil while initilizing MongoDb server ...",ex);
          } catch (IOException e) {
              log.error("IOException in MongoDBUtil while initilizing MongoDb server ...",e);
          } catch (Exception e) {
              log.error("Exception in MongoDBUtil while initilizing MongoDb server ...",e);
          } finally {
              if(fis != null) {
                  try {
                      fis.close();
                  } catch (IOException e) {
                      log.error("Exception in MongoDBUtil while closing the input stream...", e);
                  }
              }
          }
      }
  </code></pre>
  
  <p>But if restart the server, the problem is solved. It seems the driver is not able to detect the changes after killing instances. Please help. Thanks. </p>