Skip to content

Commit aa146fb

Browse files
committed
JAVA-384: NPE in case of IOException with a single server connection
1 parent d0fb480 commit aa146fb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/main/com/mongodb/DBTCPConnector.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,25 @@ public String getConnectPoint(){
282282
return master != null ? master.toString() : null;
283283
}
284284

285+
/**
286+
* This method is called in case of an IOException.
287+
* It will potentially trigger a checkMaster() to check the status of all servers.
288+
* @param t the exception thrown
289+
* @param slaveOk slaveOk flag
290+
* @return true if the request should be retried, false otherwise
291+
* @throws MongoException
292+
*/
285293
boolean _error( Throwable t, boolean slaveOk )
286294
throws MongoException {
295+
if (_rsStatus == null) {
296+
// single server, no need to retry
297+
return false;
298+
}
299+
300+
// the replset has at least 1 server up, try to see if should switch master
301+
// if no server is up, we wont retry until the updater thread finds one
302+
// this is to cut down the volume of requests/errors when all servers are down
287303
if ( _rsStatus.hasServerUp() ){
288-
// the replset has at least 1 server up, try to see if should switch master
289304
checkMaster( true , !slaveOk );
290305
}
291306
return _rsStatus.hasServerUp();

0 commit comments

Comments
 (0)