Details
-
Task
-
Resolution: Done
-
Major - P3
-
None
-
None
-
None
Description
I try to connect to not existing database.
Following code does not return error after 60 sec of running.
MongoClient client = MongoClients.create();
|
MongoDatabase db = client.getDatabase("test"); |
|
|
CountDownLatch latch = new CountDownLatch(1); |
db.listCollectionNames().subscribe(new Subscriber<>() { |
@Override |
public void onSubscribe(final Subscription subscription) { |
System.out.println("onSubscribe is called"); |
subscription.request(Long.MAX_VALUE);
|
}
|
|
|
@Override |
public void onNext(final String s) { |
System.out.println("onNext is called: " + s); |
}
|
|
|
@Override |
public void onError(final Throwable throwable) { |
System.out.println("onError is called"); |
throwable.printStackTrace();
|
latch.countDown();
|
}
|
|
|
@Override |
public void onComplete() { |
System.out.println("Complete is called"); |
latch.countDown();
|
}
|
});
|
|
|
System.out.println("Waiting finished with " + latch.await(60, TimeUnit.SECONDS)); |
Further it prints on console:
.. Exception in monitor thread while connecting to server localhost:27017
|
org.mongodb.driver.cluster - No server chosen by ReadPreferenceServerSelector ... Waiting for 30000 ms before timing out
|
...
|
Wait finished with false
|
This means that onError() was not called.
When MongoClient is created with serverSelectionTimeout option as below:
MongoClient client = MongoClients.create(MongoClientSettings.builder()
|
.applyToClusterSettings(builder -> builder.serverSelectionTimeout(1, TimeUnit.SECONDS)) |
.build());
|
Execution result is:
onSubscribe is called
|
... org.mongodb.driver.cluster - Exception in monitor thread while connecting to server 127.0.0.1:2701 ...
|
... (after 1 sec) ...
|
onError is called
|
com.mongodb.MongoTimeoutException: Timed out after 1000 ms while waiting for a server ...
|
...
|
Wait finished with true
|
|
Both cases are unacceptable for me.
Database connection error should return immediately.
Attachments
Issue Links
- is related to
-
DRIVERS-1030 Drivers should check out an implicit session only after checking out a connection
-
- Closed
-