[CDRIVER-2284] Invalidate generated BSON instead of freezing read and write concerns Created: 14/Sep/17  Updated: 28/Oct/23  Resolved: 23/Nov/17

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: 1.7.0
Fix Version/s: 1.9.0

Type: Improvement Priority: Major - P3
Reporter: Jeremy Mikola Assignee: Jeremy Mikola
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CDRIVER-2274 _mongoc_write_command_init() may free... Closed
Related
related to CDRIVER-2318 _mongoc_read_concern_freeze() assert ... Closed

 Description   

Currently, read concern and write concern objects are frozen at the first time that _mongoc_read_concern_get_bson() and _mongoc_write_concern_get_bson() are called, respectively. Once frozen, the objects can no longer be modified via the public API (setter functions will fail). This effectively caches the generated BSON internally.

Because freezing converts a mutable struct into an immutable value, libmongoc needs to copy user-supplied structs before attempting to convert them to BSON (see: WRITE_CONCERN_DOC()); however, there are still outstanding cases with collection-level write functions where we do not make copies and may inadvertently freeze the user's struct (as noted in CDRIVER-2274).

Consider removing the frozen state on these objects and instead have setter functions simply invalidate any previously generated BSON. Such a change would also let us remove the WRITE_CONCERN_DOC() macro and resolve CDRIVER-2274.



 Comments   
Comment by Githook User [ 23/Nov/17 ]

Author:

{'name': 'Jeremy Mikola', 'username': 'jmikola', 'email': 'jmikola@gmail.com'}

Message: CDRIVER-2284 validate wtimeout before calling setter

_mongoc_write_concern_new_from_iter must validate wtimeout before it
calls mongoc_write_concern_set_wtimeout, which ignores invalid
values.
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/50c18313428ac95d80b8976d00683a3a1ddb63bb

Comment by Githook User [ 23/Nov/17 ]

Author:

{'name': 'Jeremy Mikola', 'username': 'jmikola', 'email': 'jmikola@gmail.com'}

Message: CDRIVER-2284 don't worry about freezing WC in find_and_modify_with_opts

_mongoc_write_concern_get_bson() will no longer leave the write concern
immutable, so we can remove the macro for copying the write concern if
it was not already frozen.
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/fe4ba77f67c0f2b3fbbd57c33c07e39b8b361b26

Comment by Githook User [ 23/Nov/17 ]

Author:

{'name': 'Jeremy Mikola', 'username': 'jmikola', 'email': 'jmikola@gmail.com'}

Message: CDRIVER-2284 keep read and write concerns mutable

Previously, converting a read or write concern to BSON would freeze the
struct for further modification. This repurposes the "frozen" boolean
to track whether the struct has changed since its BSON was compiled and
allows further modification to unfreeze the struct (i.e. invalidate the
compiled BSON).

This also changes _mongoc_write_concern_new_from_iter() to use existing
new and setter functions to ensure that is_default is correctly
reported.
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/3db74e6265aa75823ee5d58b8aa17efa5ab50c8c

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