[SERVER-46674] Comparing RWC by converting to BSON is not robust to concurrent FCV changes Created: 06/Mar/20  Updated: 29/Oct/23  Resolved: 12/Mar/20

Status: Closed
Project: Core Server
Component/s: Replication, Sharding
Affects Version/s: None
Fix Version/s: 4.4.0-rc0, 4.7.0

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

Issue Links:
Backports
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.4
Sprint: Sharding 2020-03-23
Participants:
Linked BF Score: 30

 Description   

The serialisation of read/write concern may or may not include the provenance field, depending on the FCV. This means that if FCV is upgraded concurrently, such that one side of the BSON comparison includes provenance but the other doesn't, then the comparison result will be spurious.

The only place this occurs is when making sure that commands don't alter the writeConcern during their runtime:

https://github.com/mongodb/mongo/blob/r4.5.0/src/mongo/db/service_entry_point_common.cpp#L788

        // With the exception of getMores inheriting the WriteConcern from the originating command,
        // nothing in run() should change the writeConcern.
        dassert(command->getLogicalOp() == LogicalOp::opGetMore
                    ? !extractedWriteConcern
                    : (extractedWriteConcern &&
                       SimpleBSONObjComparator::kInstance.evaluate(
                           opCtx->getWriteConcern().toBSON() == extractedWriteConcern->toBSON())));

Possible solutions (in my suggested order of preference):

  1. Stop doing this comparison via BSON, and instead add a way to properly compare the internal fields of the WriteConcernOptions.
  2. Add a bool forceProvenance = false parameter to WriteConcernOptions::toBSON(), which is passed as true in these invocations.
  3. After generating the BSONObjs for comparison, strip out any provenance field from both objects before comparing them.

We should also improve the assertion so that it includes the conflicting writeConcerns in the message when it fails (in the non-opGetMore case).



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

Author:

{'email': 'kevin.pulo@mongodb.com', 'name': 'Kevin Pulo', 'username': 'devkev'}

Message: SERVER-46674 Compare WriteConcernOptions properly (without converting to BSON)

(cherry picked from commit 339fe2c4fda1d54912f6d175caee4d8c3c801b71)
Branch: v4.4
https://github.com/mongodb/mongo/commit/cd4d915d3eebd793620e88eb7a4b102aae756274

Comment by Githook User [ 12/Mar/20 ]

Author:

{'username': 'devkev', 'name': 'Kevin Pulo', 'email': 'kevin.pulo@mongodb.com'}

Message: SERVER-46674 Compare WriteConcernOptions properly (without converting to BSON)
Branch: master
https://github.com/mongodb/mongo/commit/339fe2c4fda1d54912f6d175caee4d8c3c801b71

Generated at Thu Feb 08 05:12:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.