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

Driver does not shutdown gracefully if maxConnectionIdleTime or maxConnectionLifeTime is set

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • 2.12.5
    • None
    • None

    Description

      The sample code that reproduces the problem:

      1
      import java.util.ArrayList;
      2
      import java.util.List;
      3
      import com.mongodb.MongoClient;
      4
      import com.mongodb.MongoClientOptions;
      5
      import com.mongodb.ReadPreference;
      6
      import com.mongodb.ServerAddress;
      7
       
      8
      public class Test {
      9
      	public static void main(String[] args) {
      10
      		System.out.println("starting!!!");
      11
      		Test.test();
      12
      		System.out.println("end!!!");
      13
      	}
      14
       
      15
      	public static void test(){
      16
      		MongoClient mongoClient = null;
      17
      		MongoClientOptions options = null;
      18
      		List<ServerAddress> serverList = null;
      19
      		try {
      20
      			serverList = new ArrayList<ServerAddress>();
      21
              		serverList.add(new ServerAddress("localhost"));
      22
      			options = new MongoClientOptions.Builder().readPreference(ReadPreference.secondary())
      23
      					.maxConnectionIdleTime(1)
      24
      					.maxConnectionLifeTime(1)
      25
      					.build();
      26
      	    	mongoClient = new MongoClient (serverList, options);
      27
      		} catch (Exception exception) {
      28
      			exception.printStackTrace();
      29
      		}
      30
       
      31
      	}
      32
      }
      

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: