-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.12.5
-
Component/s: Connection Management
If a 0 connection timeout is defined, it will causes an exception.
MongoClientOptions.Builder options = MongoClientOptions.builder(); options.connectTimeout(0); MongoClientURI mongoClientURI = new MongoClientURI("mongodb://127.0.0.1:27017", options); MongoClient mongoClient = new MongoClient(mongoClientURI); DB db = mongoClient.getDB("test"); DBCollection collection = db.getCollection("test"); System.out.println(collection.findOne());
Exception in thread "main" com.mongodb.MongoTimeoutException: Timed out after 0 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=localhost:27017, type=Unknown, state=Connecting}] at com.mongodb.BaseCluster.getDescription(BaseCluster.java:128) at com.mongodb.DBTCPConnector.getClusterDescription(DBTCPConnector.java:393) at com.mongodb.DBTCPConnector.getType(DBTCPConnector.java:565) at com.mongodb.DBTCPConnector.isMongosConnection(DBTCPConnector.java:367) at com.mongodb.Mongo.isMongosConnection(Mongo.java:645) at com.mongodb.DBCollection.findOne(DBCollection.java:865) at com.mongodb.DBCollection.findOne(DBCollection.java:843) at com.mongodb.DBCollection.findOne(DBCollection.java:789) at com.mongodb.DBCollection.findOne(DBCollection.java:778) at MongoTest.main(MongoTest.java:27) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
That behaviour doesn't match the driver documentation.
I believe the following is one of the things on 2.12 that causes the behaviour because is obtaining the maximum wait time choosing the minimal value including the connectTimeOut.