title: Why does PyMongo throw AutoReconnect?
body: <p>While researching some strange issues with my Python web application (in particular, issues regarding MongoDB connectivity), I noticed something <a href="http://api.mongodb.org/python/current/api/pymongo/errors.html" rel="noreferrer">on the official PyMongo documentation page</a>. My web application uses Flask, but this shouldn't influence the issue I'm facing.</p>
  
  <p>The PyMongo driver does connection pooling, but it also throws an exception (<code>AutoReconnect</code>) when a connection is stale and a reconnect is due. </p>
  
  <p>It states that (regarding the AutoReconnect exception):</p>
  
  <blockquote>
    <p>In order to auto-reconnect you must handle this exception, recognizing
    that the operation which caused it has not necessarily succeeded.
    Future operations will attempt to open a new connection to the
    database (and will continue to raise this exception until the first
    successful connection is made).</p>
  </blockquote>
  
  <p>I have noticed that this actually happens constantly (and it doesn't seem to be an error). Connections are closed by the MongoDB server after what seems like several minutes of inactivity, and need to be recreated by the web application.</p>
  
  <p>What I don't understand it why the PyMongo driver throws an error when it reconnects (which the user of the driver needs to handle themselves), instead of doing it transparently. (There could even be an option a user could set so that <code>AutoReconnect</code> exceptions <em>do</em> get thrown, but wouldn't a sensible default be that these exceptions don't get thrown at all, and the connections are recreated seamlessly?) </p>
  
  <p>I have never encountered this behavior using other database systems, which is why I'm a bit confused.</p>
  
  <p>It's also worth mentioning that my web application's MongoDB connections never fail when connecting to my local development MongoDB server (I assume it would have something to do with the fact that it's a local connection, and that the connection is done through a UNIX socket instead of a network socket, but I could be wrong).</p>