Skip to content

Commit 66655fe

Browse files
committed
RUBY-3790 new backpressure-connection-checkin spec test
1 parent 8db6431 commit 66655fe

File tree

2 files changed

+75
-12
lines changed

2 files changed

+75
-12
lines changed

lib/mongo/session.rb

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def with_transaction(options = nil)
458458
overload_error_count = 0
459459
overload_encountered = false
460460

461-
loop do
461+
loop do # rubocop:disable Metrics/BlockLength
462462
if transaction_attempt > 0
463463
if overload_encountered
464464
delay = @client.retry_policy.backoff_delay(overload_error_count)
@@ -539,11 +539,10 @@ def with_transaction(options = nil)
539539
if deadline_expired?(deadline) ||
540540
(e.is_a?(Error::OperationFailure::Family) && e.max_time_ms_expired?)
541541
transaction_in_progress = false
542-
if @with_transaction_timeout_ms && deadline_expired?(deadline)
543-
make_timeout_error_from(e, 'CSOT timeout expired during withTransaction commit')
544-
else
545-
raise
546-
end
542+
543+
raise unless @with_transaction_timeout_ms && deadline_expired?(deadline)
544+
545+
make_timeout_error_from(e, 'CSOT timeout expired during withTransaction commit')
547546
end
548547

549548
if e.label?('SystemOverloadedError')
@@ -1401,12 +1400,9 @@ def backoff_would_exceed_deadline?(deadline, backoff_seconds)
14011400
# In CSOT mode raises TimeoutError with last_error's message included as a substring.
14021401
# In non-CSOT mode re-raises last_error directly.
14031402
def make_timeout_error_from(last_error, timeout_message)
1404-
if @with_transaction_timeout_ms
1405-
raise Mongo::Error::TimeoutError, "#{timeout_message}: #{last_error}"
1406-
else
1407-
raise last_error
1408-
end
1409-
end
1403+
raise Mongo::Error::TimeoutError, "#{timeout_message}: #{last_error}" if @with_transaction_timeout_ms
14101404

1405+
raise last_error
1406+
end
14111407
end
14121408
end
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
description: tests that connections are returned to the pool on retry attempts for overload errors
2+
schemaVersion: "1.3"
3+
runOnRequirements:
4+
- minServerVersion: "4.4"
5+
topologies:
6+
- replicaset
7+
- sharded
8+
- load-balanced
9+
createEntities:
10+
- client:
11+
id: client
12+
useMultipleMongoses: false
13+
observeEvents:
14+
- connectionCheckedOutEvent
15+
- connectionCheckedInEvent
16+
- client:
17+
id: fail_point_client
18+
useMultipleMongoses: false
19+
- database:
20+
id: database
21+
client: client
22+
databaseName: backpressure-connection-checkin
23+
- collection:
24+
id: collection
25+
database: database
26+
collectionName: coll
27+
tests:
28+
- description: overload error retry attempts return connections to the pool
29+
operations:
30+
- name: failPoint
31+
object: testRunner
32+
arguments:
33+
client: fail_point_client
34+
failPoint:
35+
configureFailPoint: failCommand
36+
mode: alwaysOn
37+
data:
38+
failCommands:
39+
- find
40+
errorLabels:
41+
- RetryableError
42+
- SystemOverloadedError
43+
errorCode: 2
44+
- name: find
45+
object: collection
46+
arguments:
47+
filter: {}
48+
expectError:
49+
isError: true
50+
isClientError: false
51+
expectEvents:
52+
- client: client
53+
eventType: cmap
54+
events:
55+
- connectionCheckedOutEvent: {}
56+
- connectionCheckedInEvent: {}
57+
- connectionCheckedOutEvent: {}
58+
- connectionCheckedInEvent: {}
59+
- connectionCheckedOutEvent: {}
60+
- connectionCheckedInEvent: {}
61+
- connectionCheckedOutEvent: {}
62+
- connectionCheckedInEvent: {}
63+
- connectionCheckedOutEvent: {}
64+
- connectionCheckedInEvent: {}
65+
- connectionCheckedOutEvent: {}
66+
- connectionCheckedInEvent: {}
67+

0 commit comments

Comments
 (0)