[CDRIVER-3537] Pooled clients should clear state when pushed back onto the pool Created: 12/Feb/20  Updated: 31/Mar/22

Status: Backlog
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

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

Issue Links:
Depends
is depended on by CXX-1939 Revisit deprecation of client read_co... Backlog
Duplicate
is duplicated by CDRIVER-3878 reset client options when returning t... Closed
Related
is related to CDRIVER-938 Prohibit setting options on pooled cl... Backlog

 Description   

Currently we have documented for mongoc_client_set_read_concern:

It is a programming error to call this function on a client from a mongoc_client_pool_t. For pooled clients, set the read concern with the MongoDB URI instead.

I believe the reason it is considered a programming error is that it persists on the mongoc_client_t even after being pushed back onto the pool. For example:

   pool = mongoc_client_pool_new (uri);
   client = mongoc_client_pool_pop (pool);
   rc = mongoc_read_concern_new ();
   mongoc_read_concern_set_level (rc, MONGOC_READ_CONCERN_LEVEL_AVAILABLE);
   mongoc_client_set_read_concern (client, rc);
   mongoc_client_pool_push (pool, client);
   client = mongoc_client_pool_pop (pool);
   level = mongoc_read_concern_get_level (mongoc_client_get_read_concern (client));
   printf ("rc=%s\n", level); /* prints "rc=available" */
   mongoc_read_concern_destroy (rc);

This behavior seems surprising and error prone. I think the same applies to write concern and read preference. I think it would be simple enough to have mongoc_client_pool_push reset its state (clear the read/write concern and read preference) before being pushed back onto a pool.



 Comments   
Comment by Andreas Braun [ 18/Mar/21 ]

CDRIVER-3929 adds an `is_pooled` flag to `mongoc_client_t` that is used to prevent changing the server API version on a client checked out from a pool. For read concern and other options it may still be feasible to reset them when the client is checked back into the pool.

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