Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1252

Should invalidate connection pool when ServerMonitor detects a disconnect

    XMLWordPrintableJSON

Details

    Description

      When restarting mongodb, the first request after mongodb has restarted fails.

      import com.mongodb.DB;
      import com.mongodb.MongoClient;
      import com.mongodb.MongoClientOptions;
      import org.junit.Before;
      import org.junit.Test;
       
      public class TestMongoReconnection {
       
          public static final int RESTART_DELAY = 20000;
          private MongoClient mongoClient;
       
          @Before
          public void setUp() throws Exception {
       
              MongoClientOptions mongoClientOptions = MongoClientOptions.builder()
      //                .heartbeatFrequency(10) //check every 10ms
                      .build();
       
              mongoClient = new MongoClient("127.0.0.1", mongoClientOptions);
          }
       
          @Test
          public void first_request_after_mongo_restart_should_success() throws Exception {
       
              DB db = mongoClient.getDB("test");
              db.getCollectionNames();
       
              System.out.println(String.format("you have %sms to restart your mongodb server before the test resumes", RESTART_DELAY));
              Thread.sleep(RESTART_DELAY);
       
              db.getCollectionNames();
          }
      }

      The DefaultServer$DefaultServerStateListener class should call connectionProvider.invalidate(); if the state changed from connected to connecting

      Attachments

        Activity

          People

            jeff.yemin@mongodb.com Jeffrey Yemin
            dchau David CHAU
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: