Skip to content

Commit dc9e04b

Browse files
ac000hanumantmk
authored andcommitted
client pool: Add some missing locking in _push()
Commit a8c1da4 ("Client pool tries to repair unhealthy connections...") introduced more code to mongoc_client_pool_push() operating on the connection pool. However locking was missing on the first if () section which deals with various aspects of the connection pool and requires locking. Protect the if () with a mongoc_mutex_lock/unlock using pool->mutex. Signed-off-by: Andrew Clayton <[email protected]>
1 parent dce728c commit dc9e04b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/mongoc/mongoc-client-pool.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,14 @@ mongoc_client_pool_push (mongoc_client_pool_t *pool,
198198
bson_return_if_fail(pool);
199199
bson_return_if_fail(client);
200200

201+
mongoc_mutex_lock(&pool->mutex);
201202
if (pool->size > pool->min_pool_size) {
202203
mongoc_client_t *old_client;
203204
old_client = _mongoc_queue_pop_head (&pool->queue);
204205
mongoc_client_destroy (old_client);
205206
pool->size--;
206207
}
208+
mongoc_mutex_unlock(&pool->mutex);
207209

208210
if ((client->cluster.state == MONGOC_CLUSTER_STATE_HEALTHY) ||
209211
(client->cluster.state == MONGOC_CLUSTER_STATE_BORN)) {

0 commit comments

Comments
 (0)