Discussion:
[mongodb-user] Mongo Timeout Exception
anindita Basu
2018-02-14 15:45:57 UTC
Permalink
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?
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/c920e053-3cd4-43f1-a761-0a495db5b1a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Kevin Adistambha' via mongodb-user
2018-02-27 04:19:48 UTC
Permalink
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
<https://docs.mongodb.com/manual/reference/connection-string/>,
specifically the replica set option
<https://docs.mongodb.com/manual/reference/connection-string/#replica-set-option>
section.

This reconnection is a requirement outlined in Server Discovery and
Monitoring spec
<https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst>,
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
<https://github.com/mongodb/specifications/blob/master/source/sessions/driver-sessions.rst>
and retryable writes
<https://github.com/mongodb/specifications/blob/master/source/retryable-writes/retryable-writes.rst>.
Please see your specific driver’s documentation on these new features.

Best regards,
Kevin
​
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/6b704757-abf0-4397-991f-7bc9fe2a338a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...