[JAVA-1432] Auto Reconnect Created: 08/Sep/14 Updated: 11/Sep/19 Resolved: 23/Jun/15 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | 2.12.3 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Trivial - P5 |
| Reporter: | Mohamed Nouh | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
| Description |
|
I'm currently using the java driver, we've noticed that this is not auto reconnecting to mongodb by default. The below says autoConnectRetry has been deprecated, how can I use the connectTimeout property to have auto retry? @Deprecated Deprecated. There is no replacement for this method. Use the connectTimeout property to control connection timeout. Parameters: |
| Comments |
| Comment by Jeffrey Yemin [ 23/Sep/14 ] | |||||||||||||||||||||
|
I think this last exception is a Mule issue, not a Java driver issue. See for example https://www.mulesoft.org/jira/browse/MULE-6085. | |||||||||||||||||||||
| Comment by Mohamed Nouh [ 23/Sep/14 ] | |||||||||||||||||||||
|
About 10 seconds before the restart of the server. I will run some more tests. In addition, if we start the application while Mongo is unavailable, we currently receive this error repeatedly:
| |||||||||||||||||||||
| Comment by Jeffrey Yemin [ 22/Sep/14 ] | |||||||||||||||||||||
|
This doesn't surprise me, since all the threads are waking up at the same time. How close to the wakeup time did you restart the server? One thing you can do is to increase the heartbeat frequency using com.mongodb.MongoClientOptions.Builder#heartbeatFrequency. It defaults to checking each server every 5 seconds, but if you bring that up to, for example, every 0.5 seconds, you'll see fewer read operation failures. | |||||||||||||||||||||
| Comment by Mohamed Nouh [ 22/Sep/14 ] | |||||||||||||||||||||
|
Thanks Jeff, Main Sleeping for 30 seconds... | |||||||||||||||||||||
| Comment by Jeffrey Yemin [ 20/Sep/14 ] | |||||||||||||||||||||
|
The short answer here is that your code has to handle occasional failure situations when servers go down. But the driver will eventually reconnect when the server comes back online. Try running this small test program to see what I mean:
While it's running, shut down and restart mongod as often as you like and observe the behavior of the program as you do so. | |||||||||||||||||||||
| Comment by Mohamed Nouh [ 20/Sep/14 ] | |||||||||||||||||||||
|
I'm connecting to a standalone, but the code passes a list of server addresses to the MongoClient. There is only one element in the list. | |||||||||||||||||||||
| Comment by Jeffrey Yemin [ 20/Sep/14 ] | |||||||||||||||||||||
|
No, autoConnectRetry is not going to help. Are you connecting to a standalone, a replica set, or a mongos? | |||||||||||||||||||||
| Comment by Mohamed Nouh [ 20/Sep/14 ] | |||||||||||||||||||||
|
Hi Jeff, I do not see that exception over and over, it only appears when I invoke the search. After bringing up Mongo, I've waited 10+ minutes, but had no luck getting it to restablish connection. Only way right now seems for me to manually restart the app. Should I be setting the autoConnectRetry to true? It seems deprecated according to the documentation. Regards, | |||||||||||||||||||||
| Comment by Jeffrey Yemin [ 20/Sep/14 ] | |||||||||||||||||||||
|
Hi Mohamed, Do you see the above exception over and over again until you restart the application? After you bring mongod back up, how long are you waiting for the application to recover before restarting it? | |||||||||||||||||||||
| Comment by Mohamed Nouh [ 20/Sep/14 ] | |||||||||||||||||||||
|
Hi Jeff, Sorry for the delay. See below stack trace. What I've done is essentially shutdown mongo and bring it back up, the application doesn't seem to reconnect. Restarting the application, connection is established fine.
| |||||||||||||||||||||
| Comment by Jeffrey Yemin [ 08/Sep/14 ] | |||||||||||||||||||||
|
Please post a full stack trace in a comment. I'd like to know exactly what you mean when you say that the driver is not auto-reconnecting. Also, please let us know if your application is connecting to a standalone, a replica set, or a mongos, and what is happening with your MongoDB servers during the time when you're experiencing a problem. |