Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-2615

Do not allow a session to be used with an unacknowledged write concern

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.10.0, 1.10.1
    • Affects Version/s: 1.9.0
    • Component/s: None
    • None

      Per the Driver Session spec:

      Therefore drivers MUST NOT send a session ID with unacknowledged writes under any circumstances:

      • For unacknowledged writes with an explicit session, drivers SHOULD raise an error. If a driver allows users to provide an explicit session with an unacknowledged write (e.g. for backwards compatibility), the driver MUST NOT send the session ID.
      • For unacknowledged writes without an explicit session, drivers SHOULD NOT use an implicit session. If a driver creates an implicit session for unacknowledged writes without an explicit session, the driver MUST NOT send the session ID.

      Drivers MUST document the behavior of unacknowledged writes for both explicit and implicit sessions.

      While researching this in PHPC-1163, I realized that libmongoc also does not enforce this. Using APM, we should test that lsid fields are omitted from command documents for the following cases:

      • Executing a write operation or command with an explicit unacknowledged write concern
      • Executing a write operation or command with an inherited unacknowledged write concern
      • Executing a write operation or command with an explicit unacknowledged write concern and an explicit session
      • Executing a write operation or command with an inherited unacknowledged write concern and an explicit session

      The spec states that drivers "SHOULD raise an error" when explicit sessions are mixed with unacknowledged writes, but I noticed that _mongoc_write_opmsg() silently omits the session in that case. That function is used for insert/update/delete and bulk writes, so I would propose we do the same for commands and findAndModify.

      There is already a test_unacknowledged() case in the test suite, but it looks like the APM callback doesn't assert anything for unacknowledged write concerns.

      Note: users could technically add a "writeConcern" field to their command document without using the "writeConcern" option for command_with_opts(), but I don't think we want to both inspecting that.

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: