[JAVA-1246] If two instances of the same standalone server is passed to MongoClient, the driver removes it from the cluster monitor Created: 14/May/14  Updated: 30/Jan/15  Resolved: 16/Jun/14

Status: Closed
Project: Java Driver
Component/s: Cluster Management
Affects Version/s: 2.12.1
Fix Version/s: 2.12.3, 3.0.0

Type: Bug Priority: Minor - P4
Reporter: Damien Raude-Morvan Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Java 1.7
Debian GNU/Linux
Single node mongo (dev)



 Description   

Hi,

I've just upgraded our dev. environnement from Mongo Java Driver 2.11.4 to 2.12.1 and I'm getting the following error at each startup of our application :

mai 14, 2014 12:05:40 PM com.mongodb.MultiServerCluster handleStandAloneChanged
Grave: Expecting a single StandAlone, but found more than one.  Removing localhost:27017 from client view of cluster.

FYI, I'm using MongoClient(List<ServerAddress> seeds, MongoClientOptions options) constructor so that's my ClusterConnectionMode is "Multiple".

  • In production / staging, I'm providing multiple servers members of replicaset without any issue
  • In devel, I'm providing only a single ServerAddress, localhost:27017 which seems to be the source of this issue

Going deeper into Mongo Java driver code, I've found that my *ClusterSettings* hosts attribute, contains duplicate values : I can find twice "localhost:27017" ! It seems that hosts should be a Set instead of List.

Regards,



 Comments   
Comment by Githook User [ 30/Jan/15 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-1246: Removed duplicates from hosts list parameter to ClusterSettings.Builder.hosts(). Also, throw if hosts list is null or empty.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/47c000bac1473e4d4f8126844d46dfcda249b03e

Comment by Githook User [ 01/Aug/14 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-1246: Removed duplicates from hosts list parameter to ClusterSettings.Builder.hosts(). Also, throw if hosts list is null or empty.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/768bf3c8e9c9987677643c039d0e97dbd8fda99e

Comment by Githook User [ 16/Jun/14 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-1246: Removed duplicates from hosts list parameter to ClusterSettings.Builder.hosts(). Also, throw if hosts list is null or empty.
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/47c000bac1473e4d4f8126844d46dfcda249b03e

Comment by Githook User [ 16/Jun/14 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-1246: Removed duplicates from hosts list parameter to ClusterSettings.Builder.hosts(). Also, throw if hosts list is null or empty.
Branch: 2.12.x
https://github.com/mongodb/mongo-java-driver/commit/768bf3c8e9c9987677643c039d0e97dbd8fda99e

Comment by Jeffrey Yemin [ 14/May/14 ]

I changed priority to Minor since there is an easy workaround.

Comment by Jeffrey Yemin [ 14/May/14 ]

Never mind, you're totally right. I re-opened this issue.

Comment by Damien Raude-Morvan [ 14/May/14 ]

I perfectly understand that you want to keep public API as-is (ie. with a List<ServerAddress>), that's not my point. I was only suggesting to use a Set as internal storage instead of a List.
but, JTFR, this is not an harmless message since handleStandAloneChanged() method will remove all server from configuration (please launch my test case if you want more information)

I'll open a separate issue for this feature request for requesting that the MongoClient constructor check for duplicates..

Comment by Jeffrey Yemin [ 14/May/14 ]

We can't change the public API to be a Set, as that would break binary compatibility. If you'd like, you can report another issue requesting that the MongoClient constructor check for duplicates.

Regardless, the message that is being logged is harmless.

Comment by Damien Raude-Morvan [ 14/May/14 ]

Hi,

I took some time to review my issue and you're right : my application had a corner case in its configurable handling which might send *same server address* multiple times on MongoClient constructor.

So here is a snippet of code that will create trigger the "Expecting a single StandAlone, but found more than one" exception :

        MongoClient mongo = new MongoClient(Arrays.asList(
                new ServerAddress("localhost", 27017),
                new ServerAddress("localhost", 27017)),
                MongoClientOptions.builder().build()
        );
        DB db = mongo.getDB("local");
        DBCollection col = db.getCollection("startup_log");
        System.out.println(col.count());

Finally, I think that the main issue - which is not really that critical - is that MongoClient doesn't enforce ServerAddress equals/hashCode contract by using a Set to store them.

Regards,

Comment by Jeffrey Yemin [ 14/May/14 ]

I'm not able to reproduce this. I wrote a test program creating a MongoClient like this:

        MongoClient mongo = new MongoClient(Arrays.asList(new ServerAddress("localhost", 27017)), MongoClientOptions.builder().build());

where the server running on 27017 is a standalone.

I confirmed that ClusterSettings.hosts contains just single ServerAddress and did not observe the log message that you did.

Can you confirm that you're doing the same thing, in particular that your application is not passing more than one ServerAddress to the MongoClient constructor?

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