slacy/minimongo

Handle AutoReconnects

superbobry opened this issue · 5 comments

Create a new Connection automatically, once pymongo.errors.AutoReconnect is raised.

My understanding was that the default behavior of pymongo was to auto-reconnect. Did you see this error in practice?

FYI, I've been busy with my work and will be getting back to your code as soon as I can, maybe tomorrow, but maybe after the weekend.

Well, pymongo does reconnect in some cases i'm not yet sure when it does, actually -- but try reloading mongod with the code running and see what happens :)

By the way, what do you think about readthedocs.org? should we upload the docs there?

Yeah, readthedocs.org looks great. Would be happy to have the docs hosted there.

I haven't tried a shutdown/restart with minimongo clients. :) I'm sure interesting things happen. So, yeah, having some handling for this would be nice.

Can we do this without wrapping every pymongo API access in a try block? That would be ideal, or I guess we could write a decorator for that.

Okay, this is a little unexpected, I've tried two test cases and everything seems to work fine. Here's the server bit: https://gist.github.com/886138

  1. MongoDB crashes with the server running and the comes back in a while.
    $ sudo /etc/init.d/mongodb start
    $ python server.py
    * Running on http://127.0.0.1:5000/
    $ curl localhost:5000
    0
    $ sudo /etc/init.d/mongodb stop
    $ curl localhost:5000
    ... internal error ...
    $ sudo /etc/init.d/mongodb start
    $ curl localhost:5000
    0
  2. MongoDB starts after the server has already started, then crashes and comes back.
    $ python server.py
    * Running on http://127.0.0.1:5000/
    $ curl localhost:5000
    ... internal error ...
    $ sudo /etc/init.d/mongodb start
    $ curl localhost:5000
    0
    $ sudo /etc/init.d/mongodb stop
    $ curl localhost:5000
    ... internal error ...
    $ sudo /etc/init.d/mongodb start
    $ curl localhost:5000
    0

So probably we don't have to do anything about the current Connection code :)

We saw an issue with this where minimongo (and PyMongo) did not handle AutoReconnect (or Master Has Changed) exceptions well. This is with the latest versions of MongoDB, PyMongo, minimongo. See issue #28 for details and a stack trace.