[CDRIVER-3623] _mongoc_client_set_apm_callbacks_private accesses shared topology state without locking Created: 15/Apr/20  Updated: 28/Oct/23  Resolved: 20/Apr/20

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: None
Fix Version/s: 1.17.0-beta2, 1.17.0

Type: Bug Priority: Major - P3
Reporter: Kevin Albertson Assignee: Kevin Albertson
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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.



 Comments   
Comment by Githook User [ 25/May/20 ]

Author:

{'name': 'Kevin Albertson', 'email': 'kevin.albertson@mongodb.com', 'username': 'kevinAlbs'}

Message: CDRIVER-3623 fix setting apm in pooled client
Branch: r1.17
https://github.com/mongodb/mongo-c-driver/commit/0afcc3181794dbf783d45ae0d0c88e34ef37a9a0

Comment by Githook User [ 20/Apr/20 ]

Author:

{'name': 'Kevin Albertson', 'email': 'kevin.albertson@mongodb.com', 'username': 'kevinAlbs'}

Message: CDRIVER-3623 fix setting apm in pooled client
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/ba1387f0b1b92e4533801e0269baea3817c95d06

Generated at Wed Feb 07 21:18:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.