seedstack / website

SeedStack website source.
http://seedstack.org
Creative Commons Attribution Share Alike 4.0 International
4 stars 17 forks source link

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

Open alejavigo opened 3 years ago

alejavigo commented 3 years ago

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