[CSHARP-4799] Pipeline stage with BsonDocumentSearchDefinition can be rendered only once Created: 20/Sep/23  Updated: 28/Oct/23  Resolved: 04/Oct/23

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 2.22.0

Type: Bug Priority: Major - P3
Reporter: Boris Dogadov Assignee: Boris Dogadov
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

The issue as described to me by Boris is that if a caller to Render modifies the returned BsonDocument then a subsequent call to Render returns the modified BsonDocument.

This could be resolved by clarifying ownership rules of the mutable BsonDocument. Only the owner of the BsonDocument should modify it.

Most likely this would mean that that BsonDocumentSearchDefinition should own the BsonDocument, which in turn means that callers to Render should not modify the returned BsonDocument because they don't own it. However, such a rule can't be enforced at compile time because BsonDocument is mutable.

Alternatively, BsonDocumentSearchDefinition could make a defensive copy of the BsonDocument before returning it from Render (and possibly in the constructor as well to protect the document even further). This approach would be safe but involves more memory allocations.



 Comments   
Comment by Githook User [ 04/Oct/23 ]

Author:

{'name': 'BorisDog', 'email': 'BorisDog@users.noreply.github.com', 'username': 'BorisDog'}

Message: CSHARP-4799: Pipeline stage with BsonDocumentSearchDefinition can be rendered only once (#1188)
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/00a0c7230a590f09683f77c04faf3247a722b58e

Comment by Robert Stam [ 20/Sep/23 ]

Note that there are other similar classes that return an owned BsonDocument from their Render method on the assumption that callers won't modify the returned BsonDocument. So the consistent thing to do would be for callers of this Render method to also not modify the returned BsonDocument.

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