selectel / mongoDB-haskell

MongoDB driver for Haskell
http://hackage.haskell.org/package/mongoDB
Apache License 2.0
21 stars 11 forks source link

Support for auto reconnect #14

Open wereHamster opened 10 years ago

wereHamster commented 10 years ago

It would be nice to have this option so that the driver automatically reconnects to the server if the connection goes down.

gregwebs commented 10 years ago

can you give more details on this? Is this an option that should be set?

wereHamster commented 10 years ago

Some other mongodb drivers have an option, called something like auto_reconnect, which will instruct the driver to automatically reconnect to the server if the connection goes down (due to server restart, or when a replica set elects a new master).

Examples from other drivers:

gregwebs commented 10 years ago

Why not always attempt to automatically re-connect? I am wondering if this is functionality that can be built into resource-pool rather than mongoDB. Probably should switch to resource-pool before trying to implement this.

wereHamster commented 10 years ago

Automatic reconnect by default? That would work for me as well :)

gregwebs commented 10 years ago

I saw this in my error logs:

PersistMongoDBError "ConnectionFailure <socket: 4>: hGetBuf: resource vanished (Connection reset by peer)"

Is that what you saw also? (Minus the Persist wrapper if you aren't using persistent)

wereHamster commented 10 years ago

I don't have access the the logs anymore. But the symptom was that after I restarted, the application didn't work anymore.

gregwebs commented 10 years ago

after you restarted the database?

wereHamster commented 10 years ago

Oh, I deleted too much text while editing the comment, should have read 'after I restarted mongodb, the app...'

gregwebs commented 10 years ago

I was easily able to write a one-off for mongodb-queue that does this

https://github.com/docmunch/haskell-mongodb-queue/blob/master/Database/MongoDB/Queue.hs#L158