Skip to content

Refactor with transactions#3008

Draft
comandeo-mongo wants to merge 19 commits intomongodb:masterfrom
comandeo-mongo:refactor-with-transactions
Draft

Refactor with transactions#3008
comandeo-mongo wants to merge 19 commits intomongodb:masterfrom
comandeo-mongo:refactor-with-transactions

Conversation

@comandeo-mongo
Copy link
Copy Markdown
Contributor

No description provided.

comandeo-mongo and others added 19 commits March 26, 2026 15:38
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Mongo::Error::PoolTimeout does not exist; replace with StandardError
which covers all connection-related errors (SocketError, pool checkout
timeouts, NoServerAvailable, etc.).
Per DRIVERS-3391 / transactions-convenient-api spec, withTransaction must
propagate a TimeoutError (wrapping the last transient error as .cause) when
the CSOT deadline is exhausted, instead of re-raising the raw error.

Changes to lib/mongo/session.rb:
- Callback raises TransientTransactionError + deadline expired: raise
  TimeoutError in CSOT mode, re-raise original in non-CSOT mode.
- Commit raises UnknownTransactionCommitResult + deadline expired: same.
- Commit raises TransientTransactionError + deadline expired: same.
- Backoff (regular and overload) would exceed deadline: use new
  make_timeout_error_from helper — CSOT wraps last_error with cause,
  non-CSOT raises last_error directly (fixes incorrect TimeoutError
  that was raised in non-CSOT mode before this change).
- Commit overload backoff would exceed deadline: raise TimeoutError in
  CSOT mode, re-raise in non-CSOT mode.
- Add make_timeout_error_from private helper implementing the
  makeTimeoutError(lastError) pseudocode from the spec. Uses an inner
  begin/rescue to wire .cause when called outside a rescue block.

New spec/mongo/session/with_transaction_timeout_spec.rb covers all eight
code paths as unit tests with stubbed time control (no real server needed).
The test expected TimeoutError from a non-CSOT with_transaction call.
Per the spec, non-CSOT mode re-raises the original error directly.
Add timeout_ms: 5000 to enable CSOT so the test matches its intent.
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.

1 participant