Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions lib/mongo/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def with_transaction(options = nil)
overload_error_count = 0
overload_encountered = false

loop do
loop do # rubocop:disable Metrics/BlockLength
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

# rubocop:disable Metrics/BlockLength without a corresponding rubocop:enable will disable this cop for the remainder of the file. Add a matching # rubocop:enable Metrics/BlockLength after the loop block (or use a disable/enable pair around the minimal span) so the suppression is scoped appropriately.

Copilot uses AI. Check for mistakes.
if transaction_attempt > 0
if overload_encountered
delay = @client.retry_policy.backoff_delay(overload_error_count)
Expand Down Expand Up @@ -539,11 +539,10 @@ def with_transaction(options = nil)
if deadline_expired?(deadline) ||
(e.is_a?(Error::OperationFailure::Family) && e.max_time_ms_expired?)
transaction_in_progress = false
if @with_transaction_timeout_ms && deadline_expired?(deadline)
make_timeout_error_from(e, 'CSOT timeout expired during withTransaction commit')
else
raise
end

raise unless @with_transaction_timeout_ms && deadline_expired?(deadline)

make_timeout_error_from(e, 'CSOT timeout expired during withTransaction commit')
end

if e.label?('SystemOverloadedError')
Expand Down Expand Up @@ -1401,12 +1400,9 @@ def backoff_would_exceed_deadline?(deadline, backoff_seconds)
# In CSOT mode raises TimeoutError with last_error's message included as a substring.
# In non-CSOT mode re-raises last_error directly.
def make_timeout_error_from(last_error, timeout_message)
if @with_transaction_timeout_ms
raise Mongo::Error::TimeoutError, "#{timeout_message}: #{last_error}"
else
raise last_error
end
end
raise Mongo::Error::TimeoutError, "#{timeout_message}: #{last_error}" if @with_transaction_timeout_ms

raise last_error
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ tests:
commandName: bulkWrite


- description: 'database.aggregate retries using operation loop'
- description: 'database.aggregate read retries using operation loop'
operations:
- name: failPoint
object: testRunner
Expand Down Expand Up @@ -743,7 +743,7 @@ tests:
commandName: aggregate


- description: 'collection.aggregate retries using operation loop'
- description: 'collection.aggregate read retries using operation loop'
operations:
- name: failPoint
object: testRunner
Expand Down Expand Up @@ -2344,7 +2344,7 @@ tests:
commandName: dropIndexes


- description: 'collection.aggregate retries using operation loop'
- description: 'collection.aggregate write retries using operation loop'
operations:
- name: failPoint
object: testRunner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ tests:
- commandFailedEvent:
commandName: bulkWrite

- description: 'database.aggregate retries at most maxAttempts=5 times'
- description: 'database.aggregate read retries at most maxAttempts=5 times'
operations:
- name: failPoint
object: testRunner
Expand Down Expand Up @@ -513,7 +513,7 @@ tests:
- commandFailedEvent:
commandName: aggregate

- description: 'collection.aggregate retries at most maxAttempts=5 times'
- description: 'collection.aggregate read retries at most maxAttempts=5 times'
operations:
- name: failPoint
object: testRunner
Expand Down Expand Up @@ -1711,7 +1711,7 @@ tests:
- commandFailedEvent:
commandName: dropIndexes

- description: 'collection.aggregate retries at most maxAttempts=5 times'
- description: 'collection.aggregate write retries at most maxAttempts=5 times'
operations:
- name: failPoint
object: testRunner
Expand Down
Loading