I keep getting errors when writing to mongo at unpredictable times and would like to find out the reason.
I am using the mgo driver for Go. The error is of type net.OpError
. Some of its relevant fields:
net.OpError{
Err: net.timeoutError,
Op: "read",
Net: "tcp",
}
Currently I handle this error by reconnecting:
err := myType.mgoCollection.Insert(msg)
if err != nil {
myType.mgoSession = myType.mgoSession.Copy()
myType.mgoCollection = myType.mgoSession.DB("my_db_name").C("my_collection_name")
}
and re-submit. Sometimes this is enough, sometimes several retries are needed. And sometimes even after 10 retries (each around 1 minute) the error is still there (currently I break up after 10 retries).
I could not find anything suspicious in the mongodb logs and do not know where to look further.
Most of my writes to mongo are rather small, but twice a second there are somewhat larger writes (maybe 1 or 10 kb when represented as JSON string).
I have two separate processes and this error occurs for both of them at the same time.