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.
- is depended on by
-
CXX-1518 Prohibit using unacknowledged writes with explicit sessions
- Closed
-
DRIVERS-456 Prohibit using unacknowledged writes with explicit sessions
- Closed
-
PHPC-1126 Prohibit using unacknowledged writes with explicit sessions
- Closed
- is related to
-
CDRIVER-2432 Unacknowledged writes should not include transaction ID or lsid for retryable writes
- Closed
-
PHPC-1163 Do not allow a session to be used with an unacknowledged write concern
- Closed
-
DRIVERS-456 Prohibit using unacknowledged writes with explicit sessions
- Closed