Rarely I see a EOF error from mgo in my logs. Searching about this issue I came across this discussion where it is suggested that it would be safe to put a session.Refresh()
at the start of the loop to handle this issue other issues like socket error, timeout etc.
However I couldn't find if my loop should be like this where the collection (*mgo.Collection) is re-assigned after each Refresh():
session := // create mgo session
var collection *mgo.Collection
for{
session.Refresh()
collection := session.DB("dbname").C("collectionName")
....
}
OR like below where collection is assigned once outside the loop:
session := // create mgo session
collection := session.DB("dbname").C("collectionName")
for{
session.Refresh()
....
}
Posting this since I am not able to simulate this issue at will