[CDRIVER-2561] mongoc_handshake_data_append is not thread-safe Created: 21/Mar/18  Updated: 28/Oct/23  Resolved: 13/Jun/18

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: None
Fix Version/s: 1.11.0

Type: Bug Priority: Minor - P4
Reporter: A. Jesse Jiryu Davis Assignee: Evgeni Dobranov
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 Description   

Multiple threads could execute mongoc_handshake_data_append concurrently, causing undefined behavior. _mongoc_handshake_freeze() isn't thread-safe either, although it updates a global variable.

mongoc_handshake_data_append is an undocumented function intended for closely integrated drivers like PHPC, but it should be safe to use regardless.



 Comments   
Comment by Githook User [ 13/Jun/18 ]

Author:

{'username': 'edobranov', 'name': 'Evgeni Dobranov', 'email': 'evobranov@gmail.com'}

Message: CDRIVER-2561 make handshake_data_append threadsafe
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/8c519bc3425bd40a70562418cea5b558674478ac

Comment by Kevin Albertson [ 06/Jun/18 ]

For some context, drivers send an initial handshake on the first connection to a server. This handshake sends metadata to the server to identify the connection in logs, currentOp, or profiling. Drivers that wrap around the C driver can customize the client.driver and client.platform fields of the handshake metadata. They call mongoc_handshake_data_append to do so.

Comment by A. Jesse Jiryu Davis [ 22/Mar/18 ]

mongoc_init should create a mutex that protects this data, then anything that touches it must hold the mutex

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