Replica-set Connection Timeout Issue with WritableServerSelector

1,163 views
Skip to first unread message

Chandramouli Putta

unread,
Jul 20, 2016, 1:09:49 AM7/20/16
to mongodb-user
Hi there,

I have an annoying problem with the java driver connecting to a replica set in the remote environment.

I am using the below code to connect to the server through Mongo DB Java Async API 3.2.2.

      MongoClient mongoClusterClient = MongoClients.create(MongoClientSettings.builder()
                                    .clusterSettings(ClusterSettings.builder()
                                          .applyConnectionString(hrvuConnectionString)
                                          .requiredClusterType(ClusterType.REPLICA_SET)
                                          .mode(ClusterConnectionMode.MULTIPLE)
                                          .serverSelectionTimeout(120, TimeUnit.SECONDS)
                                          .serverSelector(new WritableServerSelector())
                                          .build())
                                          .connectionPoolSettings(ConnectionPoolSettings.builder()
                                                        .applyConnectionString(hrvuConnectionString)
                                                        .build())
                                                        .serverSettings(ServerSettings.builder().build())
                                                        .credentialList(getMongoConnectionString().getCredentialList())
                                                        .sslSettings(SslSettings.builder()
                                                            .applyConnectionString(hrvuConnectionString)
                                                            .build())
                                                            .socketSettings(SocketSettings.builder()
                                                                .applyConnectionString(hrvuConnectionString)
                                                                .build())
                                                                .build());
      return mongoClusterClient;

My connection string takes the below format.


I tried with different options in the client creation (supplying hosts instead of the connection string for the ClusterSettings) but always ended up with the below problem:

2016-07-14 06:54:28.797 [I] [                                ] [org.mongodb.driver.cluster] | No server chosen by WritableServerSelector from cluster description ClusterDescription{type=UNKNOWN, connectionMode=MULTIPLE, all=[ServerDescription{address=node-a.singlenode-mongodb.qa.shared.eu.qa.aws.app.io:27017, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=node-b.singlenode-mongodb.qa.shared.eu.qa.aws.app.io:27017, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=node-c.singlenode-mongodb.qa.shared.eu.qa.aws.app.io:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out

What is more interesting is after reporting this, the application is obtaining the connections independently. And there is no problem with the single DB server that is installed in my local environment. Application is functioning as expected in the local setup.

I see that it needs to get the primary node for db writes (node-a.singlenode-mongodb.qa.shared.eu.qa.aws.app.io in this case). My understanding is supplying a new instance of WritableServerSelector in the ClusterSettings while creating the client will be enough to select primaries using the selector's select method and it is proving wrong with this problem.

Is there a way to tell the driver about the primary node while connecting? I am stuck with this error for the last 3 days and any help is highly appreciated.

Thank you,
Chandra.
Reply all
Reply to author
Forward
0 new messages