diff --git a/lib/mongo/session.rb b/lib/mongo/session.rb index ab5fa18be4..d185e68e57 100644 --- a/lib/mongo/session.rb +++ b/lib/mongo/session.rb @@ -458,7 +458,7 @@ def with_transaction(options = nil) overload_error_count = 0 overload_encountered = false - loop do + loop do # rubocop:disable Metrics/BlockLength if transaction_attempt > 0 if overload_encountered delay = @client.retry_policy.backoff_delay(overload_error_count) @@ -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') @@ -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 diff --git a/spec/spec_tests/data/client_backpressure/backpressure-retry-loop.yml b/spec/spec_tests/data/client_backpressure/backpressure-retry-loop.yml index d29e17d707..5b1f064641 100644 --- a/spec/spec_tests/data/client_backpressure/backpressure-retry-loop.yml +++ b/spec/spec_tests/data/client_backpressure/backpressure-retry-loop.yml @@ -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 @@ -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 @@ -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 diff --git a/spec/spec_tests/data/client_backpressure/backpressure-retry-max-attempts.yml b/spec/spec_tests/data/client_backpressure/backpressure-retry-max-attempts.yml index 1cfabda6fd..36be3fb8f5 100644 --- a/spec/spec_tests/data/client_backpressure/backpressure-retry-max-attempts.yml +++ b/spec/spec_tests/data/client_backpressure/backpressure-retry-max-attempts.yml @@ -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 @@ -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 @@ -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