[JAVA-4509] Unable to specify the "reconnectTries" and "reconnectInterval" settings Created: 01/Mar/22  Updated: 04/May/22  Resolved: 01/Mar/22

Status: Closed
Project: Java Driver
Component/s: Configuration
Affects Version/s: 4.5.0
Fix Version/s: None

Type: Question Priority: Unknown
Reporter: Gab St-Pierre Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: external-user
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Summary

I could not find, in any of the provided Settings builders, __ how to modify the "reconnect" options. I would really like to reduce the total timeout to less than 5 seconds. I've tried using "connectTimeout", "maxWaitTime", "readTimeout", "maxConnectionIdleTime".

Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

Local mongodb instance with java driver (sync) 4.5.0.

How to Reproduce

MongoClient client = MongoClients.create(MongoClientSettings.builder().<what_here?>.build();
MongoDatabase database = client.getDatabase("test");
database.listCollectionNames().first(); // takes 30s before timeout...

 

Additional Background

Please provide any additional background information that may be helpful in diagnosing the bug.



 Comments   
Comment by Gab St-Pierre [ 01/Mar/22 ]

Thank you, I've successfully managed to apply such a configuration with the following options (to work both remotely and locally) :

.applyToClusterSettings(builder -> builder.serverSelectionTimeout(5, TimeUnit.SECONDS))
.applyToConnectionPoolSettings(builder -> builder.maxConnectionIdleTime(5, TimeUnit.SECONDS))

The `serverSelectionTimeout` was indeed needed for the remote cluster to timeout faster.

Thanks you again!

Comment by Jeffrey Yemin [ 01/Mar/22 ]

There is currently no way to specify a single timeout for the whole operation. But for the case when no server is available to send a request to, you can reduce the default 30 second timeout to 5 seconds with code like this:

        MongoClients.create(
                MongoClientSettings.builder()
                        .applyToClusterSettings(builder -> 
                                builder.serverSelectionTimeout(5, TimeUnit.SECONDS))
                        .build());

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