Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommended option for "remote/cloud" MongoDB connections #86

Open
alejavigo opened this issue Jul 7, 2021 · 0 comments
Open

Recommended option for "remote/cloud" MongoDB connections #86

alejavigo opened this issue Jul 7, 2021 · 0 comments
Assignees

Comments

@alejavigo
Copy link

The default configuration for java mongoDB driver make pooled connections to stay forever alive, and that may lead to SocketException ("Connection timed up") errors when connecting to remote/cloud MongoDB servers. This seems not to be a problem for direct MongoDB connections (DB server in same network).
Remote DB servers (or involved systems/hardware between the application and those servers) may kill the pooled connections after a period of time and the application won't realize until it tries to use the connection. The application will recover from the error as the pool is discarded and new connections will be open, but the operation/call that tried to use the broken connection will fail and get lost in the process.

Using the connection option "maxIdleTimeMS" in the connection uri or the client "options" yaml section will avoid this kind of problems.
URI Example:
mongodb://{{db_mongo_username}}:{{db_mongo_user_password}}@{{db_feedback_host}}:{{db_feedback_port}}/{{db_mongo_database_name}}?maxIdleTimeMS=120000
(120 seconds is recommended in MongoDB documentation for related tcp_keepalive problems so it can be applied to this option also )

http://docs.mongodb.org/manual/reference/connection-string/#maxIdleTimeMS

@adrienlauer adrienlauer self-assigned this Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants