Skip to content

DRIVERS-3436 - Refine withTransaction timeout error wrapping semantics and label propagation in spec and prose tests#1920

Open
nhachicha wants to merge 6 commits intomasterfrom
nh/backpressure/DRIVERS-3436
Open

DRIVERS-3436 - Refine withTransaction timeout error wrapping semantics and label propagation in spec and prose tests#1920
nhachicha wants to merge 6 commits intomasterfrom
nh/backpressure/DRIVERS-3436

Conversation

@nhachicha
Copy link
Copy Markdown
Contributor

@nhachicha nhachicha commented Apr 2, 2026

DRIVERS-3436

Updates the named prose test to be consistent with the first two cases.

Please complete the following before merging:

  • Is the relevant DRIVERS ticket in the PR title?

@nhachicha nhachicha changed the title Fixes DRIVERS-3436 [DRIVERS-3436] Clarify withTransaction timeout error label propagation in spec and prose tests Apr 2, 2026
@nhachicha nhachicha self-assigned this Apr 2, 2026
@nhachicha nhachicha force-pushed the nh/backpressure/DRIVERS-3436 branch from b16260a to 56ae0ad Compare April 2, 2026 15:36
@nhachicha nhachicha force-pushed the nh/backpressure/DRIVERS-3436 branch from 56ae0ad to 3398035 Compare April 2, 2026 15:52

3. Otherwise, propagate the `commitTransaction` error (see Note 1 below) to the caller of `withTransaction` and
return immediately.
3. Otherwise, propagate the `commitTransaction` error (see
Copy link
Copy Markdown
Contributor Author

@nhachicha nhachicha Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert to the previous behaviour see #1920 (comment)


4. Otherwise, propagate the callback's error (see Note 1 below) to the caller of `withTransaction` and return
immediately.
4. Otherwise, propagate the callback's error (see
Copy link
Copy Markdown
Contributor Author

@nhachicha nhachicha Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* {ok:1, writeConcernError: {code: 50, codeName: "MaxTimeMSExpired"}}
*/
lastError = error;
if (Date.now() - startTime >= timeout) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was removed because in sections 7.4 & 10.3 of the [sequence-of-actions|https://github.com/mongodb/specifications/blob/master/source/transactions-convenient-api/transactions-convenient-api.md#sequence-of-actions] the errors are not retriable, and they are mainly the reason for returning immediately from withTransaction. So there's no need to wrap them in a TimeoutError (if Timeout is encountered)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, in section 10.1.1 (UnknownTransactionCommitResult encountered during commit) The error is retriable if the timeout is not exeeded. So the wrapping into a timeout error needs to happen if we are throwing

@nhachicha nhachicha changed the title [DRIVERS-3436] Clarify withTransaction timeout error label propagation in spec and prose tests [DRIVERS-3436] Refine withTransaction timeout error wrapping semantics and label propagation in spec and prose tests Apr 2, 2026
@nhachicha nhachicha requested a review from Copilot April 2, 2026 17:44
@nhachicha nhachicha changed the title [DRIVERS-3436] Refine withTransaction timeout error wrapping semantics and label propagation in spec and prose tests DRIVERS-3436 - Refine withTransaction timeout error wrapping semantics and label propagation in spec and prose tests Apr 2, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Convenient Transactions API specification and associated prose tests to clarify how withTransaction should propagate errors when the retry timeout is exceeded, including timeout error wrapping semantics and error label propagation.

Changes:

  • Adds a dedicated “timeout error propagation mechanism” section and updates step text to reference it.
  • Updates wording across the spec and tests from “raise” to “propagate” and removes “Note 1” references.
  • Adjusts pseudo-code related to timeout wrapping behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
source/transactions-convenient-api/transactions-convenient-api.md Clarifies timeout wrapping/label propagation semantics; updates step wording; modifies pseudo-code and adds a new timeout propagation section.
source/transactions-convenient-api/tests/README.md Updates prose test expectations to reference the timeout propagation mechanism and adds an assertion about label preservation.
Comments suppressed due to low confidence (1)

source/transactions-convenient-api/transactions-convenient-api.md:269

  • In the pseudo-code, the commit retry loop no longer checks whether the overall withTransaction timeout has been exceeded before retrying commitTransaction again on UnknownTransactionCommitResult. As written, this loop can continue retrying indefinitely and never raise the timeout-wrapping error required by the spec (see Sequence of Actions step 10.1). Reintroduce an elapsed-time check before continue retryCommit and throw makeTimeoutError(lastError) when the timeout is exceeded.
                lastError = error;
                if (!isMaxTimeMSExpiredError(error) &&
                    error.hasErrorLabel("UnknownTransactionCommitResult")) {
                    continue retryCommit;
                }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nhachicha nhachicha marked this pull request as ready for review April 2, 2026 18:46
@nhachicha nhachicha requested a review from a team as a code owner April 2, 2026 18:46
@nhachicha nhachicha requested review from NoahStapp, comandeo-mongo, stIncMale and vbabanin and removed request for a team and comandeo-mongo April 2, 2026 18:46
`withTransaction` should propagate the error as described in the
[propagation mechanism](../transactions-convenient-api.md#timeout-error-propagation-mechanism) to its caller.
- If committing raises an error with the `UnknownTransactionCommitResult` label, and the retry timeout has been
exceeded, `withTransaction` should propagate the error to its caller.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this point also supposed to call out the propagation mechanism?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍 I fixed the prose and the spec.
TL;DR UnknownTransactionCommitResult is retriable in the commit loop if we don't exceed the timeout, so it makes sense to wrap it into a Timeout error if we exceed the timeout and want to throw and return (as described in section 10.1.1)

@nhachicha nhachicha requested a review from NoahStapp April 3, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants