C++ Driver - Thread Sanitizer Data Race When Exception Is Thrown Using mongocxx::pool on Single Node Replica Set

I am using the MongoDB C++ Driver to develop an application that connects to a MongoDB single node replica set. I deployed the single node replica set by following this tutorial: Convert Standalone to Replica Set. I am using the MongoDB C++ Driver version r3.6.7 and the MongoDB C Driver version 1.21.2.

I have included a sample program that, when run with ThreadSanitizer (ThreadSanitizer — Clang 11 documentation), consistently detects a data race. I have a class that has a shared pointer to a mongocxx::pool as a member variable. In the constructor of that class, a client is acquired from the pool and is used to create an index. If creating the index throws an exception, the data race is detected. I have also included two screenshots of the warnings that are being generated.

Before running the program, change the host constant to be the ipAddress:port of your single node replica set. Use a username and password that will cause an Authentication Error when connecting to the database in order to see the warning. The warning does not occur when an exception is not thrown.

Sample program:

#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>

#include <mongocxx/client.hpp>
#include <mongocxx/exception/exception.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/pool.hpp>
#include <mongocxx/uri.hpp>

#include <iostream>
#include <memory>
#include <stdexcept>
#include <string>

namespace {

const mongocxx::instance MONGODB_DRIVER;

const std::string DATABASE_NAME = "testDb";
const std::string COLLECTION_NAME = "testCollection";
const std::string INDEX_FIELD = "testIndex";

using bsoncxx::builder::basic::make_document;
using bsoncxx::builder::basic::kvp;

} /* anonymous namespace */

class Test {
    Test(const std::string& uriString)
      : pool{std::make_shared<mongocxx::pool>(mongocxx::uri(uriString))}
        try {
            mongocxx::pool::entry client = pool->acquire();
            (*client)[DATABASE_NAME][COLLECTION_NAME].create_index((make_document(kvp(INDEX_FIELD, 1))), make_document(kvp("unique", true)));
        } catch (const mongocxx::exception& ex) {
			// Do nothing
	std::shared_ptr<mongocxx::pool> pool;

int main() {
    // This URI requires bad authentication so that an exception will be thrown in the Test constructor
    // Change host to the ipAdress:port of your single-node replica set
    const std::string badUsername = "mongoAdminxxx";
    const std::string password = "mongoAdmin";
    const std::string host = "localhost:27017";
    const std::string uriString = "mongodb://" + badUsername + ":" + password + "@" + host + "/?minPoolSize=0&maxPoolSize=100";

    for (uint32_t iteration = 0; iteration < 1000; ++iteration) {
		std::cout << iteration << std::endl;
        Test test(uriString);

    return 0;

To build and run the program, use commands:

/usr/bin/g++ -g --std=c++17 MongoTest.cpp -o mongotest $(pkg-config --cflags --libs libmongocxx) -fsanitize=thread

Is this a known issue? How do we resolve this?