PyMongo 1.1.1 ConnectionFailure and AutoReconnect exceptions

273 views
Skip to first unread message

TMC

unread,
Nov 19, 2009, 11:14:18 AM11/19/09
to mongodb-user
From PyMongo API documentation:
"If an operation fails because of a connection error,
ConnectionFailure is raised. If auto-reconnection will be performed,
AutoReconnect will be raised. Application code should handle this
exception (recognizing that the operation failed) and then continue to
execute."

A simple test code:
from pymongo import *
from pymongo.errors import AutoReconnect
from time import sleep
connection = Connection("localhost", None, 1, None, 10)
db = connection.test
collection = db.testing
collection.remove({})
collection.insert({"id":1})

while 1:
try:
print collection.count()
except Exception, e:
print "Exception: " + str(e)
sleep(5)

So, this outputs somthing like:
1
1
1
1

Then I try to stop-start mongod service during 5 second sleep. I
supposed to see only one AutoReconnect exception like this:

1
1
Exception: connection closed, resetting
1
1


But the first exception is ConnectionFailure. Then it keeps to thow
AutoReconnect exceptions.
1
1
Exception: timed out before acquiring a connection from the pool
Exception: connection closed, resetting
Exception: connection closed, resetting
Exception: connection closed, resetting
Exception: connection closed, resetting
Exception: connection closed, resetting

So, what is the proper way to handle short database failures/restarts
in my python code?

Michael Dirolf

unread,
Nov 20, 2009, 12:16:44 PM11/20/09
to mongod...@googlegroups.com
Sorry for the long response time.

I think the fact that you're getting a single ConnectionFailure before
getting AutoReconnect exceptions is because of a bug in PyMongo -
similar to the issue that Dave is running into in a different thread.
This should be cleaned up in the next release.

The reason you continue to get AutoReconnects is that the driver has
to wait until the master is back up (or in the case of pairing, until
the slave has promoted itself). So it's not expected to be
instantaneous.

- Mike
> --
>
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=.
>
>
>

TMC

unread,
Nov 20, 2009, 3:22:43 PM11/20/09
to mongodb-user
Hello.

> I think the fact that you're getting a single ConnectionFailure before
> getting AutoReconnect exceptions is because of a bug in PyMongo -
> similar to the issue that Dave is running into in a different thread.
> This should be cleaned up in the next release.

I see, thanks for that.


> The reason you continue to get AutoReconnects is that the driver has
> to wait until the master is back up (or in the case of pairing, until
> the slave has promoted itself). So it's not expected to be
> instantaneous.

The server is really working at the time of these exceptions. I can
use it from the shell or another python script, for example.

Michael Dirolf

unread,
Nov 20, 2009, 5:48:21 PM11/20/09
to mongod...@googlegroups.com
>> The reason you continue to get AutoReconnects is that the driver has
>> to wait until the master is back up (or in the case of pairing, until
>> the slave has promoted itself). So it's not expected to be
>> instantaneous.
>
> The server is really working at the time of these exceptions. I can
> use it from the shell or another python script, for example.

Hmm... I'll look into that. Maybe after I cut the next version (should
be soon hopefully) we can see if this is still an issue after the
changes.

Michael Dirolf

unread,
Nov 23, 2009, 4:14:47 PM11/23/09
to mongod...@googlegroups.com
Just released 1.1.2 which now should raise AutoReconnect iff the
driver will attempt an autoreconnect on the next operation. Can you
give that a shot and let us know if this is still an issue?

zahariash

unread,
Nov 25, 2009, 2:57:30 AM11/25/09
to mongodb-user
> Just released 1.1.2 which now should raise AutoReconnect iff the
> driver will attempt an autoreconnect on the next operation. Can you
> give that a shot and let us know if this is still an issue?

Version 1.1.2 works as you described. After couple of AutoReconnect
exceptions, all threads in pool are connected again.

Thanks for quick fix.

TMC

unread,
Nov 25, 2009, 7:10:48 AM11/25/09
to mongodb-user
Now it works as expected. Thank you!
Reply all
Reply to author
Forward
0 new messages