diff --git a/jstests/sharding/repl_monitor_refresh.js b/jstests/sharding/repl_monitor_refresh.js
index 4419c1438de..63865458cdc 100644
--- a/jstests/sharding/repl_monitor_refresh.js
+++ b/jstests/sharding/repl_monitor_refresh.js
@@ -3,6 +3,7 @@
  * become invalid when a replica set reconfig happens.
  * @tags: [multiversion_incompatible]
  */
+import {configureFailPoint} from "jstests/libs/fail_point_util.js";
 import {awaitRSClientHosts, reconfig} from "jstests/replsets/rslib.js";
 
 // Skip the following checks since the removed node has wrong config and is still alive.
@@ -43,6 +44,13 @@ confDoc.version++;
 
 jsTest.log('Changing conf to ' + tojson(confDoc));
 
+// Hang the stepup job.
+let stepUpFailpoints = new Map();
+st.rs0.nodes.forEach(function(node) {
+    stepUpFailpoints.set(node.host,
+                         configureFailPoint(node, 'hangReplicaSetUpdateOnConfigServerForStepUp'))
+});
+
 reconfig(replTest, confDoc);
 
 awaitRSClientHosts(mongos, {host: targetHostName}, {ok: true, ismaster: true});
@@ -55,12 +63,26 @@ assert.soon(function() {
             (res.members[2].configTerm === rsConfig.term));
 });
 
-// Remove first node from set
-confDoc.members.shift();
+// Remove non-primary node from set to avoid election of new primary.
+const hostToDrop = st.rs0.getSecondary().host;
+confDoc.members = confDoc.members.filter((member) => member.host != hostToDrop);
+jsTestLog("dropped " + hostToDrop);
+jsTestLog(confDoc);
+
 confDoc.version++;
 
+stepUpFailpoints.get(st.rs0.getPrimary().host).wait();
+
+let reconfigFP =
+    configureFailPoint(st.rs0.getPrimary(), 'hangReplicaSetUpdateOnConfigServerForReconfig');
+
 reconfig(replTest, confDoc);
 
+reconfigFP.wait();
+stepUpFailpoints.forEach((fp, key, map) => fp.off());
+sleep(5000);
+reconfigFP.off();
+
 jsTest.log("Waiting for mongos to reflect change in shard replica set membership.");
 var replView;
 assert.soon(
@@ -83,7 +105,8 @@ assert.soon(
     },
     function() {
         return ("Expected to find " + confDoc.members.length + " nodes but found " +
-                shardDoc.host.split(',').length + " in " + shardDoc.host);
+                shardDoc.host.split(',').length + " in " + shardDoc.host +
+                ". Full doc: " + tojson(shardDoc));
     });
 
 st.stop({parallelSupported: false, skipValidation: true});
diff --git a/src/mongo/db/s/sharding_initialization_mongod.cpp b/src/mongo/db/s/sharding_initialization_mongod.cpp
index e871d48cfeb..f492bad4952 100644
--- a/src/mongo/db/s/sharding_initialization_mongod.cpp
+++ b/src/mongo/db/s/sharding_initialization_mongod.cpp
@@ -617,7 +617,7 @@ void ShardingInitializationMongoD::onStepUpBegin(OperationContext* opCtx, long l
         // config shard finishes initializing after the update finishes (resulting in no updates).
         (void)ShardingReady::get(opCtx)->isReadyFuture().thenRunOn(executor).then([&]() {
             ShardRegistry::scheduleReplicaSetUpdateOnConfigServerIfNeeded(
-                [&]() -> bool { return _isPrimary.load(); });
+                [&]() -> bool { return _isPrimary.load(); }, true);
         });
     }
 }
@@ -638,7 +638,7 @@ void ShardingInitializationMongoD::onSetCurrentConfig(OperationContext* opCtx) {
     }
     if (Grid::get(opCtx)->isInitialized()) {
         ShardRegistry::scheduleReplicaSetUpdateOnConfigServerIfNeeded(
-            [&]() -> bool { return _isPrimary.load(); });
+            [&]() -> bool { return _isPrimary.load(); }, false);
     }
 }
 
diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp
index f2f7a1b0c2e..f0ba7128101 100644
--- a/src/mongo/s/client/shard_registry.cpp
+++ b/src/mongo/s/client/shard_registry.cpp
@@ -91,6 +91,9 @@ const Seconds kRefreshPeriod(30);
 
 const Backoff kExponentialBackoff(Seconds(1), Milliseconds::max());
 
+MONGO_FAIL_POINT_DEFINE(hangReplicaSetUpdateOnConfigServerForStepUp);
+MONGO_FAIL_POINT_DEFINE(hangReplicaSetUpdateOnConfigServerForReconfig);
+
 }  // namespace
 
 namespace shard_registry_stats {
@@ -494,13 +497,13 @@ SharedSemiFuture<ShardRegistry::Cache::ValueHandle> ShardRegistry::_reloadAsync(
 }
 
 void ShardRegistry::scheduleReplicaSetUpdateOnConfigServerIfNeeded(
-    const std::function<bool()>& isPrimaryFn) noexcept {
+    const std::function<bool()>& isPrimaryFn, bool onStepUp) noexcept {
     if (!isPrimaryFn()) {
         return;
     }
 
     auto executor = Grid::get(getGlobalServiceContext())->getExecutorPool()->getFixedExecutor();
-    AsyncTry([] {
+    AsyncTry([onStepUp] {
         ThreadClient tc("UpdateReplicaSetOnConfigServer",
                         getGlobalServiceContext()->getService(ClusterRole::ShardServer));
 
@@ -537,6 +540,11 @@ void ShardRegistry::scheduleReplicaSetUpdateOnConfigServerIfNeeded(
             return Status::OK();
         }
 
+        if (onStepUp && hangReplicaSetUpdateOnConfigServerForStepUp.shouldFail()) {
+            logd("hangReplicaSetUpdateOnConfigServerForStepUp hit");
+            hangReplicaSetUpdateOnConfigServerForStepUp.pauseWhileSet(opCtx);
+        }
+
         auto replSetConfigVersion = replCoord->getConfig().getConfigVersion();
         // Specify the config version in the filter and the update to prevent overwriting a
         // newer connection string when there are concurrent updates.
@@ -546,6 +554,12 @@ void ShardRegistry::scheduleReplicaSetUpdateOnConfigServerIfNeeded(
         auto update = BSON("$set" << BSON(ShardType::host()
                                           << connStr.toString() << ShardType::replSetConfigVersion()
                                           << replSetConfigVersion));
+
+
+        if (!onStepUp && hangReplicaSetUpdateOnConfigServerForReconfig.shouldFail()) {
+            logd("hangReplicaSetUpdateOnConfigServerForReconfig hit");
+            hangReplicaSetUpdateOnConfigServerForReconfig.pauseWhileSet(opCtx);
+        }
         auto swWasUpdated = grid->catalogClient()->updateConfigDocument(
             opCtx,
             NamespaceString::kConfigsvrShardsNamespace,
diff --git a/src/mongo/s/client/shard_registry.h b/src/mongo/s/client/shard_registry.h
index f5e0f3ea525..a100674cf6b 100644
--- a/src/mongo/s/client/shard_registry.h
+++ b/src/mongo/s/client/shard_registry.h
@@ -347,7 +347,7 @@ public:
      * error, retries if the mongod is still a primary.
      */
     static void scheduleReplicaSetUpdateOnConfigServerIfNeeded(
-        const std::function<bool()>& isPrimaryFn) noexcept;
+        const std::function<bool()>& isPrimaryFn, bool onStepUp) noexcept;
 
     /*
      * Returns true if the given host is part of the config server replica set.
