Mongo Timeout Exception

296 views
Skip to first unread message

anindita Basu

unread,
Feb 14, 2018, 2:41:30 PM2/14/18
to mongodb-user

I am getting following exception 



8-02-14 00:46:31.317 [cluster-ClusterId{value='5a81a50d4f91084ea47121eb', description='null'}-maas-gt-p41-l0001.nam.nsroot.net:37017 5a81a50e4f91084ea47121ee  ] INFO  (cluster info Line:76) Exception in monitor thread while connecting to server maas-gt-p41-l0001.nam.

nsroot.net:37017

com.mongodb.MongoCommandException: Command failed with error 11600: 'interrupted at shutdown' on server maas-gt-p41-l0001.nam.nsroot.net:37017. The full response is { "ok" : 0.0, "errmsg" : "interrupted at shutdown", "code" : 11600, "codeName" : "InterruptedAtShutdown"

}



Main Question: 

Should I change application code to resolve exceptions due to primary step down and election of a new primary by opening the connection again or should I be able to handle this using the driver timeout settings and a retry of save on exception?

Kevin Adistambha

unread,
Feb 26, 2018, 11:19:48 PM2/26/18
to mongodb-user

Hi

Should I change application code to resolve exceptions due to primary step down and election of a new primary by opening the connection again or should I be able to handle this using the driver timeout settings and a retry of save on exception?

If you provide the driver with a connection URI that specifies a replica set, the driver should reconnect to the new primary as soon as it’s available. See Connection String URI Format, specifically the replica set option section.

This reconnection is a requirement outlined in Server Discovery and Monitoring spec, which all supported MongoDB driver must conform to.

Having said that, if your operation is a save() operation, it should be safe to retry (since save() rewrites the whole document). However, if your operation involve a non-idempotent operation such as $inc, it is recommended to either:

  • Check if the $inc condition is still valid in case an error happened to avoid incrementing a field twice, or
  • Change the operation to an idempotent one, which is safer (e.g. use $set instead of $inc if possible).

This situation is better handled in MongoDB 3.6, due to driver support for sessions and retryable writes. Please see your specific driver’s documentation on these new features.

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages