Why is PyMongo dropping AutoReconnect?

Studying some weird issues with my Python web application (specifically MongoDB connectivity issues), I noticed something

+6
source share
1 answer

You misunderstand AutoReconnect. It occurs when the driver tries to contact the server (to send a command or other operation), and a network failure or similar problem occurs. The name of the exception means that you do not need to create a new instance of MongoClient, the existing client will try to automatically connect when your application tries to perform the next operation. If the same problem occurs, the AutoReconnect function is added again.

I suspect that the reason you see socket timeouts (and AutoReconnect increase) is because there is load balancing between the server and your application, which closes the connections after a period of inactivity. For example, this appears to be happening on the Microsoft Azure platform after 13 minutes of inactivity on the socket. You may be able to fix this using the socketKeepAlive parameter added in PyMongo 2.8. Please note that you also need to set the keepalive interval on your application server to the appropriate value (the default for Linux is 2 hours). See here for more details .

+6
source

Source: https://habr.com/ru/post/983218/


All Articles