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

Driver does not shutdown gracefully if maxConnectionIdleTime or maxConnectionLifeTime is set

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.12.5
    • Component/s: None
    • Labels:
      None

      The sample code that reproduces the problem:

      import java.util.ArrayList;
      import java.util.List;
      import com.mongodb.MongoClient;
      import com.mongodb.MongoClientOptions;
      import com.mongodb.ReadPreference;
      import com.mongodb.ServerAddress;
      
      public class Test {
      	public static void main(String[] args) {
      		System.out.println("starting!!!");
      		Test.test();
      		System.out.println("end!!!");
      	}
      
      	public static void test(){
      		MongoClient mongoClient = null;
      		MongoClientOptions options = null;
      		List<ServerAddress> serverList = null;
      		try {
      			serverList = new ArrayList<ServerAddress>();
              		serverList.add(new ServerAddress("localhost"));
      			options = new MongoClientOptions.Builder().readPreference(ReadPreference.secondary())
      					.maxConnectionIdleTime(1)
      					.maxConnectionLifeTime(1)
      					.build();
      	    	mongoClient = new MongoClient (serverList, options);
      		} catch (Exception exception) {
      			exception.printStackTrace();
      		}
      
      	}
      }
      

      If the highlighted lines are commented out, the process quits as soon as the "end!!!" line is printed. If the lines are present, the java process stays running.

      Works fine with v3.3.0, but fails with older version.

            Assignee:
            Unassigned Unassigned
            Reporter:
            dmitry.ryabtsev@mongodb.com Dmitry Ryabtsev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: