[CDRIVER-3757] mongoc_client_pool_new does not initialize its condition variable Created: 16/Jul/20  Updated: 28/Oct/23  Resolved: 23/Jul/20

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: None
Fix Version/s: 1.18.0, 1.17.3, 1.18.0-alpha

Type: Bug Priority: Major - P3
Reporter: Andrew Witten (Inactive) Assignee: Andrew Witten (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The condition variable in mongoc_client_pool_t does not get initialized, which results in undefined behavior. As a consequence, it is possible that a call to mongoc_client_pool_pop when all clients have already been distributed may never return, even when a client becomes available.



 Comments   
Comment by Githook User [ 24/Nov/20 ]

Author:

{'name': 'Andrew Witten', 'email': 'andrew.witten@mongodb.com', 'username': 'awitten1'}

Message: CDRIVER-3757 inits pool cond, adds test (#666)

Initializes pool condition variable. Adds (non-deterministic) test for the case where a thread is waiting in call to `mongoc_client_pool_pop` for a client to become available.
Branch: r1.17
https://github.com/mongodb/mongo-c-driver/commit/64a395c1c024d3e79f6cf720f0c97b1340fcd376

Comment by Githook User [ 23/Jul/20 ]

Author:

{'name': 'Andrew Witten', 'email': 'andrew.witten@mongodb.com', 'username': 'awitten1'}

Message: CDRIVER-3757 inits pool cond, adds test (#666)

Initializes pool condition variable. Adds (non-deterministic) test for the case where a thread is waiting in call to `mongoc_client_pool_pop` for a client to become available.
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/c082789db7ddd7348c447a073bd93328e75a0783

Comment by Kaitlin Mahar [ 20/Jul/20 ]

andrew.witten No worries! Thank you for the quick reply and clarification.

Comment by Andrew Witten (Inactive) [ 20/Jul/20 ]

Hi Kaitlin. Sorry, my description wasn't clear. I will edit that now. The issue is that even when a client becomes available, the function still may not return.

mongoc_client_pool_try_pop won't be affected, because it doesn't block in the event that max_pool_size clients have already been distributed (it just returns NULL).

Comment by Kaitlin Mahar [ 20/Jul/20 ]

Hi andrew.witten, question - isn't the expected behavior of this method to not return until a new client is available? Or is the problem that even if a client later becomes available, the method might not return?

I ask because I work on the Swift driver, which wraps libmongoc, and we use mongoc_client_pool_t s to back our MongoClient type. We actually always use mongoc_client_pool_try_pop though. Would that method be affected at all by this bug?

Comment by Andrew Witten (Inactive) [ 17/Jul/20 ]

PR: https://github.com/mongodb/mongo-c-driver/pull/666

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