From aeab436accc7f83e9625be6b4483aa03a732316b Mon Sep 17 00:00:00 2001 From: Pavi Vetriselvan Date: Tue, 15 Jun 2021 16:24:21 -0400 Subject: SERVER-57715 Catch network errors during rerouted insert in inject_tenant_prefix.js --- .../libs/override_methods/inject_tenant_prefix.js | 53 +++++++++++++++------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/jstests/libs/override_methods/inject_tenant_prefix.js b/jstests/libs/override_methods/inject_tenant_prefix.js index 92031d24c91..fc9a1f11952 100644 --- a/jstests/libs/override_methods/inject_tenant_prefix.js +++ b/jstests/libs/override_methods/inject_tenant_prefix.js @@ -348,24 +348,43 @@ Mongo.prototype.recordRerouteDueToTenantMigration = function() { assert.neq(null, this.reroutingMongo); while (true) { - const res = originalRunCommand.apply(this, [ - "testTenantMigration", - { - insert: "rerouted", - documents: [{_id: this.migrationStateDoc._id}], - writeConcern: {w: "majority"} - }, - 0 - ]); - if (res.ok) { - return; - } - if (ErrorCodes.isNetworkError(res.code) || ErrorCodes.isNotPrimaryError(res.code)) { - jsTest.log("Failed to write to testTenantMigration.rerouted due to a retryable error " + - tojson(res)); - continue; + try { + const res = originalRunCommand.apply(this, [ + "testTenantMigration", + { + insert: "rerouted", + documents: [{_id: this.migrationStateDoc._id}], + writeConcern: {w: "majority"} + }, + 0 + ]); + + if (res.ok) { + break; + } else if (ErrorCodes.isNetworkError(res.code) || + ErrorCodes.isNotPrimaryError(res.code)) { + jsTest.log( + "Failed to write to testTenantMigration.rerouted due to a retryable error " + + tojson(res)); + continue; + } else { + // Throw non-retryable errors. + assert.commandWorked(res); + } + } catch (e) { + // Since the shell can throw custom errors that don't propagate the error code, check + // these exceptions for specific network error messages. + // TODO SERVER-54026: Remove check for network error messages once the shell reliably + // returns error codes. + if (ErrorCodes.isNetworkError(e.code) || ErrorCodes.isNotPrimaryError(e.code) || + isNetworkError(e)) { + jsTest.log( + "Failed to write to testTenantMigration.rerouted due to a retryable error exception " + + tojson(e)); + continue; + } + throw e; } - assert.commandWorked(res); } }; -- cgit v1.2.1