-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.10.1
-
Component/s: Connection Management
-
None
The Java driver is great when everything goes right. However, the weakness can be seen when things start to go wrong.
Let me illustrate with an example. A very simple one ... detecting when the server is available. You can't!
Say for example you wanted to make sure the server was available (maybe you start your client before the server, or the server goes away for maintenance for a few moments (backup)).
Take the following piece of code:
try{
mongo.getConnector().requestEnsureConnection();
}catch(Exception e){
// never thrown
}
Why is the following exception (see below) masked? It is logged out to the JUL but that is of no use to the calling application.
The mongo.getConnector().isOpen() also suffers the same fate.
Why on earth are these exceptions masked? This is Java 101.
WARNING: Exception executing isMaster command on /127.0.0.1:27017
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:214)
at com.mongodb.DBPort.go(DBPort.java:107)
at com.mongodb.DBPort.go(DBPort.java:88)
at com.mongodb.DBPort.findOne(DBPort.java:143)
at com.mongodb.DBPort.runCommand(DBPort.java:148)
at com.mongodb.DBTCPConnector.initDirectConnection(DBTCPConnector.java:548)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:527)
at com.mongodb.DBTCPConnector.requestEnsureConnection(DBTCPConnector.java:129)
at com.profiler.ProfilerExtension.run(ProfilerExtension.java:126)
at java.lang.Thread.run(Thread.java:619)
So the question is, how does one handle the fact a server has gone away? What is the magic here to determine what is what?
- duplicates
-
JAVA-805 Make connection pool and connection state observable
- Closed