go-bongo / bongo

Go ODM for MongoDB
MIT License
486 stars 40 forks source link

Handle reconnect #14

Closed iamsaso closed 7 years ago

iamsaso commented 7 years ago

I had to implement and easy way to reconnect the session if mongodb server was restarted or connection was dropped for any other reason. Would love to hear any suggestions if there is a better way to handle this.

securingsincity commented 7 years ago

@sasso this seems like it might be a little heavy to be making calls every n seconds, perhaps we can find a lighter touch way. I wonder if a better way is handling errored calls that receive an EOF and retry them by refreshing the session then. I found this discussion https://github.com/go-mgo/mgo/issues/49 and https://groups.google.com/forum/#!topic/mgo-users/XM0rc6p-V-8 regarding this topic.

iamsaso commented 7 years ago

I was looking into that issues and global EOF handler would be cool, I also checked my logs and i never got the EOF but connection reset so i guess there are other failures that session.ping does catch. I know this is a bit heavy but just wanted too put it here to start a discussion and find a better solution... but for now this works and helps me keep my app live when this issue occurs.