Skip to content

Commit bd801db

Browse files
committed
Collect leftover connections before capturing driver logs; note base_delay is before jitter
1 parent 8523500 commit bd801db

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

mssql_python/retry.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class RetryPolicy:
106106
max_attempts (int): Total number of tries, including the first. 1 means never retry.
107107
backoff (str): "exponential" doubles the delay after each failed attempt, "fixed"
108108
waits ``base_delay`` every time.
109-
base_delay (float): Delay in seconds before the second attempt.
109+
base_delay (float): Delay in seconds before the second attempt, before jitter.
110110
max_delay (float): Upper bound in seconds for any single delay, jitter included.
111111
jitter (bool): When True each delay is scaled by a factor drawn uniformly from
112112
[0, 1), so many clients do not reconnect in lockstep. The delay can be shorter than
@@ -136,8 +136,8 @@ def __init__(
136136
Args:
137137
max_attempts (int): Total number of tries including the first; at least 1.
138138
backoff (str): "exponential" or "fixed".
139-
base_delay (float): Seconds to wait before the second attempt; zero to 86400
140-
(one day).
139+
base_delay (float): Seconds to wait before the second attempt, before jitter;
140+
zero to 86400 (one day).
141141
max_delay (float): Cap in seconds for every delay; at least ``base_delay`` and at
142142
most 86400.
143143
jitter (bool): Scale each delay down by a random factor in [0, 1), so the wait can
@@ -180,7 +180,7 @@ def backoff(self) -> str:
180180

181181
@property
182182
def base_delay(self) -> float:
183-
"""Delay in seconds before the second attempt."""
183+
"""Delay in seconds before the second attempt, before jitter."""
184184
return self._base_delay
185185

186186
@property

tests/test_027_retry_policy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
cursor fixture is requested, so the file runs with DB_CONNECTION_STRING unset.
99
"""
1010

11+
import gc
1112
import logging
1213
import random
1314
from types import SimpleNamespace
@@ -86,6 +87,9 @@ def driver_log(caplog):
8687
8788
The driver logger does not propagate, so caplog's handler goes on it directly.
8889
"""
90+
# A failed connect() leaves a half built Connection in a reference cycle; if the collector
91+
# frees one from an earlier test inside this window, its cleanup warning would be counted.
92+
gc.collect()
8993
with caplog.at_level(logging.WARNING, logger="mssql_python"):
9094
mssql_python.logging.logger.addHandler(caplog.handler)
9195
try:

0 commit comments

Comments
 (0)