Let me try to be more specific.
So, we have bootstrap code somewhere that creates the global session:
session, err := mgo.Dial(url)
and we hold on to that.
When requests come in from the network, they'll Clone or Copy the session, and execute. What I saw this morning, when the replica set reconfigured itself b/c I executed the command:
rs.remove('url-of-a-secondary')
This caused all mgo sessions to start returning the error EOF. This should be recoverable, but it was not.
I could try do a clonedSession.Refresh() or copiedSession.Refresh() right there in the local context, but I have no idea if that would fix it or if that's the recommended way. Instead, is the recommended way to do session.Refresh() on the parent/root session?
Also, I get there can be several reasons for a failure, intermittent network issues, too many file descriptors, etc. But this issue that happened this morning *should* be recoverable, so I want to do whatever I can to make it robust.
I don't like checking for Error types in golang anymore than the next guy, but when some errors are recoverable, and you can figure that out and take some action, then it makes sense to do so.
So, would it make sense to check only for EOF as the main clue that the replica set is reconfiguring itself / or has reconfigured, and try to refresh the session at that point?
Should it be refreshed on the global root session, or would it work with any copied/cloned session?
The idea behind using Ping is so I don't have to go into hundreds and hundreds of lines of code to add an error check on a non-nil error to determine if a session refresh is necessary, but perhaps I can do it in a single spot.
Does that make more sense as a question?