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

_mongoc_client_set_apm_callbacks_private accesses shared topology state without locking

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.17.0-beta2, 1.17.0
    • Affects Version/s: None
    • Component/s: libmongoc
    • Labels:
      None

      Caught by TSAN:

      WARNING: ThreadSanitizer: data race (pid=44697)
        Read of size 8 at 0x7b64000045a0 by thread T34:
          #0 _mongoc_topology_scanner_monitor_heartbeat_succeeded mongoc-topology-scanner.c:1088 (test-libmongoc:x86_64+0x100315307)
          #1 _async_success mongoc-topology-scanner.c:469 (test-libmongoc:x86_64+0x100314c28)
          #2 _async_handler mongoc-topology-scanner.c:573 (test-libmongoc:x86_64+0x100314921)
          #3 mongoc_async_cmd_run mongoc-async-cmd.c:126 (test-libmongoc:x86_64+0x10026590f)
          #4 mongoc_async_run mongoc-async.c:160 (test-libmongoc:x86_64+0x1002651a7)
          #5 mongoc_topology_scanner_work mongoc-topology-scanner.c:1010 (test-libmongoc:x86_64+0x10031440e)
          #6 mongoc_topology_scan_once mongoc-topology.c:591 (test-libmongoc:x86_64+0x10030691d)
          #7 _mongoc_topology_run_background mongoc-topology.c:1303 (test-libmongoc:x86_64+0x100308551)
      
        Previous write of size 8 at 0x7b64000045a0 by main thread (mutexes: write M794):
          #0 memmove <null>:1598704 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x30398)
          #1 mongoc_topology_set_apm_callbacks mongoc-topology.c:381 (test-libmongoc:x86_64+0x1003061a2)
          #2 _mongoc_client_set_apm_callbacks_private mongoc-client.c:2692 (test-libmongoc:x86_64+0x10027adef)
          #3 _initialize_new_client mongoc-client-pool.c:237 (test-libmongoc:x86_64+0x10027e6bc)
          #4 mongoc_client_pool_pop mongoc-client-pool.c:262 (test-libmongoc:x86_64+0x10027e1fe)
          #5 test_mongoc_handshake_pool test-mongoc-client.c:3102 (test-libmongoc:x86_64+0x100122411)
          #6 TestSuite_RunTest TestSuite.c:586 (test-libmongoc:x86_64+0x10025b30a)
          #7 TestSuite_RunSerial TestSuite.c:857 (test-libmongoc:x86_64+0x10025a17d)
          #8 TestSuite_Run TestSuite.c:959 (test-libmongoc:x86_64+0x10025962d)
          #9 main test-libmongoc.c:2507 (test-libmongoc:x86_64+0x1000b9b3b)
      

      _mongoc_client_set_apm_callbacks_private overwrites the callbacks on the topology object without holding the topology mutex.

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

              Created:
              Updated:
              Resolved: