diff --git a/source/retryable-writes/retryable-writes.rst b/source/retryable-writes/retryable-writes.rst index 1c7e3382eb..b1604d8c14 100644 --- a/source/retryable-writes/retryable-writes.rst +++ b/source/retryable-writes/retryable-writes.rst @@ -455,6 +455,7 @@ The above rules are implemented in the following pseudo-code: retryableCommand = addTransactionIdToCommand(command, session); Exception previousError = null; + retrying = false; while true { try { return executeCommand(server, retryableCommand); @@ -468,7 +469,7 @@ The above rules are implemented in the following pseudo-code: * numbers" MUST be re-raised with an actionable error message. */ if (!currentError.hasErrorLabel("RetryableWriteError")) { - if ( currentError.code == 20 && originalError.errmsg.startsWith("Transaction numbers") ) { + if ( currentError.code == 20 && previousError.errmsg.startsWith("Transaction numbers") ) { currentError.errmsg = "This MongoDB deployment does not support retryable..."; } throw currentError; @@ -490,7 +491,7 @@ The above rules are implemented in the following pseudo-code: * from the connection pool), we should raise the previous error if there * was one. */ - if (currentError is not DriverException && ! originalError.hasErrorLabel("NoWritesPerformed")) { + if (currentError is not DriverException && ! previousError.hasErrorLabel("NoWritesPerformed")) { previousError = currentError; } } @@ -516,10 +517,18 @@ The above rules are implemented in the following pseudo-code: throw previousError; } - /* CSOT is enabled and the operation has timed out. */ - if (timeoutMS != null && isExpired(timeoutMS) { + if (timeoutMS == null) { + /* If CSOT is not enabled, allow any retryable error from the second + * attempt to propagate to our caller, as it will be just as relevant + * (if not more relevant) than the original error. */ + if (retrying) { + throw previousError; + } + } else if (isExpired(timeoutMS)) { + /* CSOT is enabled and the operation has timed out. */ throw previousError; } + retrying = true; } } @@ -829,6 +838,7 @@ inconsistent with the server and potentially confusing to developers. Changelog ========= +:2023-10-02: When CSOT is not enabled, one retry attempt occurs. :2023-08-26: Require that in a sharded cluster the server on which the operation failed MUST be provided to the server selection mechanism as a deprioritized server.