[JAVA-4244] Top level error labels aren't added to WriteConcernErrors Created: 19/Jul/21  Updated: 28/Oct/23  Resolved: 27/Jul/21

Status: Closed
Project: Java Driver
Component/s: Error Handling
Affects Version/s: None
Fix Version/s: 4.3.1, 3.12.10

Type: Bug Priority: Major - P3
Reporter: Ross Lawley Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: planned-maintenance-detectable-bug
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by JAVA-4204 Scala failover test leads to a write ... Closed
Related
related to DRIVERS-1385 Make retryable write test error label... Implementing
is related to JAVA-4204 Scala failover test leads to a write ... Closed
is related to SERVER-58195 InterruptedDueToReplStateChange missi... Closed
Case:
Documentation Changes: Not Needed

 Description   

The ProtocolHelper#createSpecialException does not apply top level error labels to the write concern error.

This can wrongly lead to errors being deemed not retryable. In particular, it means a response to a write operation like:

{
    "ok": 1.0, 
    "errorLabels": ["RetryableWriteError"],   
    "writeConcernError": {
         "code": 11602, 
         "codeName": "InterruptedDueToReplStateChange", 
         "errmsg": "operation was interrupted",
    },
    "n": 1, 
    "nModified": 1, 
    ... 
}

will not be considered by the driver to be retryable.

The retryable writes spec states here that:

The driver MUST treat all errors with the RetryableWriteError label as retryable. This error label can be found in the top-level "errorLabels" field of the error. In a server error response with a writeConcernError field the top level document or the writeConcernError document may contain the RetryableWriteError error label.

So it seems the driver is in violation of that mandate, and it seems that there are no spec tests enforcing it or the driver has implemented the spec tests incorrectly so that they pass when they should not.



 Comments   
Comment by Githook User [ 27/Jul/21 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}

Message: Add top-level error labels to write concern error (#766)

This will allow the driver to properly retry writes that the server
has labeled as a RetryableWriteError.

JAVA-4244
Branch: 4.3.x
https://github.com/mongodb/mongo-java-driver/commit/50ba959bbbb907572e8cdb6a92f964f694548a3e

Comment by Githook User [ 27/Jul/21 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}

Message: Add top-level error labels to write concern error (#766)

This will allow the driver to properly retry writes that the server
has labeled as a RetryableWriteError.

JAVA-4244
Branch: 3.12.x
https://github.com/mongodb/mongo-java-driver/commit/81cc1a7a03670f9809f4d59a7db7df6bd0bb2095

Comment by Githook User [ 27/Jul/21 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}

Message: Add top-level error labels to write concern error (#766)

This will allow the driver to properly retry writes that the server
has labeled as a RetryableWriteError.

JAVA-4244
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/07e85a995fe3d3a4dc022f09e5b02165d9e6b30d

Comment by Jeffrey Yemin [ 22/Jul/21 ]

This bug would have been caught by DRIVERS-1385.

Comment by Jeffrey Yemin [ 22/Jul/21 ]

I confirmed that there are no spec tests that enforce that drivers check for error labels at the top level when encountering a write concern error. All the tests use failpoints that look something like this:

      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "delete"
          ],
          "writeConcernError": {
            "code": 91,
            "errmsg": "Replication is being shut down",
            "errorLabels": [
              "RetryableWriteError"
            ]
          }
        }
      }

where the error label is embedded in the write concern error and not at the top level.

Generated at Thu Feb 08 09:01:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.