summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJudah Schvimer <judah@mongodb.com>2017-02-27 13:14:03 -0500
committerJudah Schvimer <judah@mongodb.com>2017-03-06 10:07:27 -0500
commit814b2fe1438fa6c2da698c68a9efdf83ef2702ae (patch)
treec7f116b70de57af332f912f90b3646fdac1cff01 /src
parent04eb46ca8ceb1862c82ea70745cf72b4cc6450e3 (diff)
downloadmongo-814b2fe1438fa6c2da698c68a9efdf83ef2702ae.tar.gz
SERVER-27839 Allow for step downs during reconfig in ReplSetTest initiate
(cherry picked from commit a4e1443629b733c7c0fd44dddcd78e884da848bd)
Diffstat (limited to 'src')
-rw-r--r--src/mongo/shell/db.js2
-rw-r--r--src/mongo/shell/replsettest.js19
-rw-r--r--src/mongo/shell/utils.js8
3 files changed, 23 insertions, 6 deletions
diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js
index 839c605e2cb..7134bea4cc6 100644
--- a/src/mongo/shell/db.js
+++ b/src/mongo/shell/db.js
@@ -331,7 +331,7 @@ var DB;
} catch (e) {
// we expect the command to not return a response, as the server will shut down
// immediately.
- if (e.message.indexOf("error doing query: failed") >= 0) {
+ if (isNetworkError(e)) {
print('server should be down...');
return;
}
diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js
index 29cee6aae9b..cab0bde19ed 100644
--- a/src/mongo/shell/replsettest.js
+++ b/src/mongo/shell/replsettest.js
@@ -725,9 +725,20 @@ var ReplSetTest = function(opts) {
// if a heartbeat times out during the quorum check. We retry three times to reduce
// the chance of failing this way.
assert.retry(() => {
- const res = master.runCommand(cmd);
- if (res.ok === 1) {
- return true;
+ var res;
+ try {
+ res = master.runCommand(cmd);
+ if (res.ok === 1) {
+ return true;
+ }
+ } catch (e) {
+ // reconfig can lead to a stepdown if the primary looks for a majority before
+ // a majority of nodes have successfully joined the set. If there is a stepdown
+ // then the reconfig request will be killed and respond with a network error.
+ if (isNetworkError(e)) {
+ return true;
+ }
+ throw e;
}
assert.commandFailedWithCode(
@@ -816,7 +827,7 @@ var ReplSetTest = function(opts) {
try {
assert.commandWorked(this.getPrimary().adminCommand({replSetReconfig: config}));
} catch (e) {
- if (tojson(e).indexOf("error doing query: failed") < 0) {
+ if (!isNetworkError(e)) {
throw e;
}
}
diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js
index 215d40de685..f9e7bb29451 100644
--- a/src/mongo/shell/utils.js
+++ b/src/mongo/shell/utils.js
@@ -37,6 +37,12 @@ function _getErrorWithCode(codeOrObj, message) {
return e;
}
+// Checks if a javascript exception is a network error.
+function isNetworkError(error) {
+ return error.message.indexOf("error doing query") >= 0 ||
+ error.message.indexOf("socket exception") >= 0;
+}
+
// Please consider using bsonWoCompare instead of this as much as possible.
friendlyEqual = function(a, b) {
if (a == b)
@@ -1180,7 +1186,7 @@ rs._runCmd = function(c) {
try {
res = db.adminCommand(c);
} catch (e) {
- if (("" + e).indexOf("error doing query") >= 0) {
+ if (isNetworkError(e)) {
// closed connection. reconnect.
db.getLastErrorObj();
var o = db.getLastErrorObj();