Skip to content

fix(NODE-7430): throw timeout error when withTransaction retries exceed deadline#4897

Merged
PavelSafronov merged 6 commits intomainfrom
NODE-7430
Apr 15, 2026
Merged

fix(NODE-7430): throw timeout error when withTransaction retries exceed deadline#4897
PavelSafronov merged 6 commits intomainfrom
NODE-7430

Conversation

@tadjik1
Copy link
Copy Markdown
Member

@tadjik1 tadjik1 commented Mar 18, 2026

Description

Summary of Changes

Align withTransaction timeout behavior with the spec change from DRIVERS-3391: when retry attempts exhaust the timeout, enforce a deadline-based check. With CSOT (timeoutMS), throw a MongoOperationTimeoutError wrapping the last transient error as cause; without CSOT (legacy 120s), propagate the last error directly.
Please keep in mind, all the recent changes from https://jira.mongodb.org/browse/DRIVERS-3436 are incorporated in this PR as well.

Spec: https://github.com/mongodb/specifications/blob/master/source/transactions-convenient-api/transactions-convenient-api.md#sequence-of-actions

Notes for Reviewers

The makeTimeoutError helper mirrors the spec's makeTimeoutError pseudocode function. It also copies error labels from the cause, so callers can check hasErrorLabel('TransientTransactionError') on the timeout error itself.

What is the motivation for this change?

NODE-7430 / DRIVERS-3391

Release Highlight

Release notes highlight

Double check the following

  • Lint is passing (npm run check:lint)
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@tadjik1 tadjik1 marked this pull request as ready for review March 18, 2026 14:39
@tadjik1 tadjik1 requested a review from a team as a code owner March 18, 2026 14:39
Copilot AI review requested due to automatic review settings March 18, 2026 14:39
Copy link
Copy Markdown
Contributor

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 driver’s withTransaction retry-timeout behavior to align with the transactions convenient API spec changes (DRIVERS-3391), ensuring that when the retry deadline is exceeded under CSOT (timeoutMS), the driver surfaces a timeout error rather than the last transient error directly.

Changes:

  • Update ClientSession.withTransaction retry loop to enforce a computed retry deadline and throw a MongoOperationTimeoutError (CSOT) that wraps the last retry-triggering error as cause.
  • Add/extend CSOT unified spec coverage for withTransaction timeout behavior, including retry scenarios with transient transaction errors.
  • Add integration prose tests to validate legacy (non-CSOT) retry-timeout enforcement via mocked time progression.

Reviewed changes

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

File Description
test/spec/client-side-operations-timeout/convenient-transactions.yml Adds CSOT unified spec coverage for withTransaction timeout and introduces additional event assertions.
test/spec/client-side-operations-timeout/convenient-transactions.json JSON equivalent of the above spec updates.
test/integration/transactions-convenient-api/transactions-convenient-api.prose.test.ts Adds prose tests to validate the legacy 120s retry timeout behavior using a stubbed clock.
src/sessions.ts Implements deadline-based retry timeout checks and introduces makeTimeoutError helper for CSOT wrapping behavior.

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

Comment thread src/sessions.ts
@PavelSafronov PavelSafronov self-assigned this Mar 20, 2026
PavelSafronov
PavelSafronov previously approved these changes Mar 20, 2026
Copy link
Copy Markdown
Contributor

@PavelSafronov PavelSafronov left a comment

Choose a reason for hiding this comment

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

Overall changes look good, just have some nit comments, but nothing blocking.

Comment thread src/sessions.ts Outdated
Comment thread src/sessions.ts Outdated
Comment thread src/sessions.ts Outdated
@dariakp dariakp self-requested a review March 22, 2026 18:52
Copy link
Copy Markdown
Contributor

@dariakp dariakp left a comment

Choose a reason for hiding this comment

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

@PavelSafronov @tadjik1 Can we address copilot's comments? They are on spec tests, but if we think they are valid, it's always an option to submit an improvement to the spec.

@dariakp dariakp added the wip label Mar 26, 2026
@tadjik1 tadjik1 added Team Review Needs review from team and removed wip labels Apr 13, 2026
@nbbeeken nbbeeken self-requested a review April 15, 2026 14:18
Copy link
Copy Markdown
Contributor

@nbbeeken nbbeeken left a comment

Choose a reason for hiding this comment

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

LGTM, no functional concerns about that processTimeMS comment, it still satisfies monotonicity

Comment thread src/sessions.ts Outdated
@PavelSafronov PavelSafronov merged commit 16a899d into main Apr 15, 2026
25 of 32 checks passed
@PavelSafronov PavelSafronov deleted the NODE-7430 branch April 15, 2026 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Team Review Needs review from team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants