I believe there is a race in this code. If the secondary which starts up has a chance to start initial sync before stopSet() is called, then the node may try to sync from another node which is getting shut down. This may cause initial sync to fail with the error message such as:
[js_test:wildcard_index_feature_compatability_version] 2018-10-08T07:58:48.546+0000 d20271| 2018-10-08T07:58:48.545+0000 I NETWORK [signalProcessingThread] shutdown: going to close listening sockets... [js_test:wildcard_index_feature_compatability_version] 2018-10-08T07:58:48.546+0000 d20271| 2018-10-08T07:58:48.545+0000 E REPL [replication-0] Initial sync failed, shutting down now. Restart the server to attempt a new initial sync. [js_test:wildcard_index_feature_compatability_version] 2018-10-08T07:58:48.546+0000 d20271| 2018-10-08T07:58:48.545+0000 I NETWORK [signalProcessingThread] removing socket file: /tmp/mongodb-20271.sock [js_test:wildcard_index_feature_compatability_version] 2018-10-08T07:58:48.546+0000 d20271| 2018-10-08T07:58:48.545+0000 F - [replication-0] Fatal assertion 40088 HostUnreachable: error while getting base rollback ID :: caused by :: Connection was closed at src/mongo/db/repl/replication_coordinator_impl.cpp 705 [js_test:wildcard_index_feature_compatability_version] 2018-10-08T07:58:48.546+0000 d20271| 2018-10-08T07:58:48.545+0000 F - [replication-0] [js_test:wildcard_index_feature_compatability_version] 2018-10-08T07:58:48.546+0000 d20271| [js_test:wildcard_index_feature_compatability_version] 2018-10-08T07:58:48.546+0000 d20271| ***aborting after fassert() failure [js_test:wildcard_index_feature_compatability_version] 2018-10-08T07:58:48.546+0000 d20271| [js_test:wildcard_index_feature_compatability_version] 2018-10-08T07:58:48.546+0000 d20271|
I think we can just fix this by adding a call to awaitReplication() before stopping the set.