[JAVA-626] race condition in DB.requestEnsureConnection can cause NullPointerException Created: 21/Aug/12  Updated: 29/Aug/12  Resolved: 22/Aug/12

Status: Closed
Project: Java Driver
Component/s: Cluster Management
Affects Version/s: None
Fix Version/s: 2.9.0

Type: Bug Priority: Critical - P2
Reporter: Barrie Segal Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related

 Description   

With a replica set connection, use of DB.requestEnsureConnection has a race condition which can cause a NullPointerException:

    java.lang.NullPointerException
	at com.mongodb.DBTCPConnector$MyPort.requestEnsureConnection(DBTCPConnector.java:483)
	at com.mongodb.DBTCPConnector.requestEnsureConnection(DBTCPConnector.java:129)
	at com.mongodb.DBApiLayer.requestEnsureConnection(DBApiLayer.java:110)MongoDBConnection.java:482

This race condition is not actually new, but the NPE happens more frequently now that the driver is handling a list of servers that can be either mongos server or replica set members.



 Comments   
Comment by Jeffrey Yemin [ 29/Aug/12 ]

Closing as part of 2.9.0 release process.

Comment by Jeffrey Yemin [ 22/Aug/12 ]

You do not need to upgrade the Java driver to 2.9.0 to use Mongo server 2.2.0. 2.8.0 is compatible.

Comment by Steve Benjamin [ 22/Aug/12 ]

Tried this version out this morning (2.9 rc2) and confirm that it fixed the error I was seeing. Thanks.

On a side note, can someone reply to the question that triggered this, which was if this version of the driver is necessary for Mongo 2.2?

Comment by auto [ 22/Aug/12 ]

Author:

{u'date': u'2012-08-21T20:52:06-07:00', u'email': u'jeff.yemin@10gen.com', u'name': u'Jeff Yemin'}

Message: JAVA-626: Fixing race condition in DBApiLayer.requestEnsureConnection
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/d05bc12612168c18c064d7732c19a31c661d1489

Comment by Steve Benjamin [ 21/Aug/12 ]

From the question "Can you please show the code for how you're creating the Mongo instance?" on CS-4182:

 //mongo options passed into the method:
		MongoOptions options = new MongoOptions();
		options.autoConnectRetry = true;
		options.socketKeepAlive = true;
		options.connectionsPerHost = maxConnections;
		options.slaveOk = false;
		options.connectTimeout = 30000;
		options.socketTimeout = 60000;
		options.threadsAllowedToBlockForConnectionMultiplier = 15;
		options.maxWaitTime = 20000;
		options.fsync = false;
		 
 
		DBAddress db1 = new DBAddress(urlString);
		List<ServerAddress> l = new ArrayList<>();
		l.add(db1);
		Mongo _mongo = new Mongo(l, options);
		_db = _mongo.getDB(db1.getDBName());

Generated at Thu Feb 08 08:52:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.