[CDRIVER-3303] Some options not applied for OP_MSG without sessions Created: 10/Aug/19  Updated: 28/Oct/23  Resolved: 07/May/20

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: None
Fix Version/s: 1.17.0-beta2, 1.17.0

Type: Task Priority: Major - P3
Reporter: Kevin Albertson Assignee: Roberto Sanchez
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CDRIVER-3070 Do not include lsid in commands if to... Closed
Related
related to CDRIVER-3657 Make command assembly more robust reg... Backlog

 Description   

mongoc_cmd_parts_assemble assembles options and the base command document into a final command to send.

parts->body is the base command, like

{insert: "coll"}


parts->assembled_body is the base command with options set, like:

{insert: "coll", "readConcern": { "level": "majority" }}

parts->assembled.command is the final assembled command to send. This either points to parts->body if no options are required to be appended to the base command, or is set to parts->assembled_body otherwise. (I think perhaps this is a micro optimization, to avoid copying the command if we don't need to.)

So, at the start of the mongoc_cmd_parts_assemble there is:

parts->assembled.command = parts->body;

And whenever an option is set, you're supposed to call
_mongoc_cmd_parts_ensure_copied, which switches it over:

parts->assembled.command = &parts->assembled_body;

My guess is that this is a micro-optimization, to avoid copying parts->body if no options were set and nothing changed. However, we don't always call _mongoc_cmd_parts_ensure_copied every time options are set, meaning we might omit sending them. I don't think it's currently possible for this to surface because this only applies when:

  • no $lsid (session ID) is appended
  • we're using OP_MSG (so, post 3.6)
  • user manually specifies $db in the command document (which is probably pretty rare)

Because of CDRIVER-3070, we always (incorrectly) assume a 3.6+ server supports sessions and append the $lsid. When that's fixed, we'll need to fix this.



 Comments   
Comment by Githook User [ 25/May/20 ]

Author:

{'name': 'Roberto C. Sánchez', 'email': 'roberto@connexer.com', 'username': 'rcsanchez97'}

Message: CDRIVER-3303 always apply command options for OP_MSG
Branch: r1.17
https://github.com/mongodb/mongo-c-driver/commit/bbd2669545e582934d5f29512901bc066cd3f546

Comment by Githook User [ 07/May/20 ]

Author:

{'name': 'Roberto C. Sánchez', 'email': 'roberto@connexer.com', 'username': 'rcsanchez97'}

Message: CDRIVER-3303 always apply command options for OP_MSG
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/a4f02b73833b2421098e55dc2ad159ccd97cef5d

Comment by Kevin Albertson [ 10/Aug/19 ]

Here is a branch with a repro (with a workaround for CDRIVER-3070)
https://github.com/kevinAlbs/mongo-c-driver/tree/cdriver3303

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