Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-4803

Resolve TSAN warning for multiple single-threaded clients

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      Summary

      Resolve an observed TSAN warning when using multiple single-threaded clients in separate threads. Here is an example stack trace when used in the C++ driver:

      [j1:prim]   Previous write of size 1 at 0x7fea109b7118 by thread T105 (mutexes: write M872989262969134504):
      [j1:prim]     #0 _mongoc_handshake_freeze /data/mci/c5a40dbcaac77d38feef2562ae860e96/src/src/mongo/db/modules/enterprise/src/streams/third_party/mongocxx/dist/mongoc/mongoc-handshake.c:569:37 (libmongoc.so+0x88398)
      [j1:prim]     #1 _mongoc_topology_do_blocking_scan /data/mci/c5a40dbcaac77d38feef2562ae860e96/src/src/mongo/db/modules/enterprise/src/streams/third_party/mongocxx/dist/mongoc/mongoc-topology.c:929:4 (libmongoc.so+0xb8591)
      [j1:prim]     #2 mongoc_topology_select_server_id /data/mci/c5a40dbcaac77d38feef2562ae860e96/src/src/mongo/db/modules/enterprise/src/streams/third_party/mongocxx/dist/mongoc/mongoc-topology.c:1234:13 (libmongoc.so+0xb8e93)
      [j1:prim]     #3 _mongoc_client_end_sessions /data/mci/c5a40dbcaac77d38feef2562ae860e96/src/src/mongo/db/modules/enterprise/src/streams/third_party/mongocxx/dist/mongoc/mongoc-client.c:3034:19 (libmongoc.so+0x5a278)
      [j1:prim]     #4 mongoc_client_destroy /data/mci/c5a40dbcaac77d38feef2562ae860e96/src/src/mongo/db/modules/enterprise/src/streams/third_party/mongocxx/dist/mongoc/mongoc-client.c:1205:10 (libmongoc.so+0x5a082)
      [j1:prim]     #5 mongocxx::v_noabi::client::impl::~impl() /data/mci/c5a40dbcaac77d38feef2562ae860e96/src/src/mongo/db/modules/enterprise/src/streams/third_party/mongocxx/dist/mongocxx/private/client.hh:33:9 (libmongocxx.so+0x6d349)
      [j1:prim]     #6 std::default_delete<mongocxx::v_noabi::client::impl>::operator()(mongocxx::v_noabi::client::impl*) const /opt/mongodbtoolchain/revisions/69f4f0673ffcb290ce2307560a4883ecf2ad138c/stow/gcc-v4.35T/lib/gcc/x86_64-mongodb-linux/11.3.0/../../../../include/c++/11.3.0/bits/unique_ptr.h:85:2 (libmongocxx.so+0x69e7a)
      [j1:prim]     #7 std::unique_ptr<mongocxx::v_noabi::client::impl, std::default_delete<mongocxx::v_noabi::client::impl> >::~unique_ptr() /opt/mongodbtoolchain/revisions/69f4f0673ffcb290ce2307560a4883ecf2ad138c/stow/gcc-v4.35T/lib/gcc/x86_64-mongodb-linux/11.3.0/../../../../include/c++/11.3.0/bits/unique_ptr.h:361:4 (libmongocxx.so+0x69e7a)
      [j1:prim]     #8 mongocxx::v_noabi::client::~client() /data/mci/c5a40dbcaac77d38feef2562ae860e96/src/src/mongo/db/modules/enterprise/src/streams/third_party/mongocxx/dist/mongocxx/client.cpp:142:17 (libmongocxx.so+0x69e7a)
      [j1:prim]     #9 std::default_delete<mongocxx::v_noabi::client>::operator()(mongocxx::v_noabi::client*) const 
      

      This may require locking gHandshakeLock around calls to _mongoc_handshake_freeze for single-threaded clients.

      The TSAN warning is currently suppressed in the C driver: https://github.com/mongodb/mongo-c-driver/blob/3f2c35d97e7f12de5da4f049dce4c3f8494aba67/.tsan-suppressions#L2

      Background & Motivation

      I expect the warning is harmless. The TSAN warning is flagging the fact that a global is being overwritten to the same value by two different threads.

      Using a mongoc_client_pool_t to obtain clients in a multi-threaded application is preferred. This may not be a commonly encountered issue. However, this was observed by an internal team and may serve as a point of confusion.

            Assignee:
            Unassigned Unassigned
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: