Skip to content

Commit 24542c9

Browse files
committed
fix backoff logic
1 parent 6d8369f commit 24542c9

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

pymongo/asynchronous/pool.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,14 +1313,7 @@ async def _get_conn(
13131313
self._raise_if_not_ready(checkout_started_time, emit_event=True)
13141314
while not (self.requests < self.max_pool_size):
13151315
timeout = deadline - time.monotonic() if deadline else None
1316-
if self._backoff and (self._backoff_connection_time > time.monotonic()):
1317-
timeout = 0.01
13181316
if not await _async_cond_wait(self.size_cond, timeout):
1319-
# Check whether we should continue to wait for the backoff condition.
1320-
if self._backoff and deadline is None or deadline < time.monotonic():
1321-
if self._backoff_connection_time > time.monotonic():
1322-
continue
1323-
break
13241317
# Timed out, notify the next thread to ensure a
13251318
# timeout doesn't consume the condition.
13261319
if self.requests < self.max_pool_size:
@@ -1339,12 +1332,19 @@ async def _get_conn(
13391332
incremented = True
13401333
while conn is None:
13411334
# CMAP: we MUST wait for either maxConnecting OR for a socket
1342-
# to be checked back into the pool.
1335+
# to be checked back into the pool OR for the backoff period to expire.
13431336
async with self._max_connecting_cond:
13441337
self._raise_if_not_ready(checkout_started_time, emit_event=False)
13451338
while not (self.conns or self._pending < self.max_connecting):
13461339
timeout = deadline - time.monotonic() if deadline else None
1340+
if self._backoff and (self._backoff_connection_time > time.monotonic()):
1341+
timeout = 0.01
13471342
if not await _async_cond_wait(self._max_connecting_cond, timeout):
1343+
# Check whether we should continue to wait for the backoff condition.
1344+
if self._backoff and deadline is None or deadline < time.monotonic():
1345+
if self._backoff_connection_time > time.monotonic():
1346+
continue
1347+
break
13481348
# Timed out, notify the next thread to ensure a
13491349
# timeout doesn't consume the condition.
13501350
if self.conns or self._pending < self.max_connecting:

pymongo/synchronous/pool.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,14 +1309,7 @@ def _get_conn(
13091309
self._raise_if_not_ready(checkout_started_time, emit_event=True)
13101310
while not (self.requests < self.max_pool_size):
13111311
timeout = deadline - time.monotonic() if deadline else None
1312-
if self._backoff and (self._backoff_connection_time > time.monotonic()):
1313-
timeout = 0.01
13141312
if not _cond_wait(self.size_cond, timeout):
1315-
# Check whether we should continue to wait for the backoff condition.
1316-
if self._backoff and deadline is None or deadline < time.monotonic():
1317-
if self._backoff_connection_time > time.monotonic():
1318-
continue
1319-
break
13201313
# Timed out, notify the next thread to ensure a
13211314
# timeout doesn't consume the condition.
13221315
if self.requests < self.max_pool_size:
@@ -1335,12 +1328,19 @@ def _get_conn(
13351328
incremented = True
13361329
while conn is None:
13371330
# CMAP: we MUST wait for either maxConnecting OR for a socket
1338-
# to be checked back into the pool.
1331+
# to be checked back into the pool OR for the backoff period to expire.
13391332
with self._max_connecting_cond:
13401333
self._raise_if_not_ready(checkout_started_time, emit_event=False)
13411334
while not (self.conns or self._pending < self.max_connecting):
13421335
timeout = deadline - time.monotonic() if deadline else None
1336+
if self._backoff and (self._backoff_connection_time > time.monotonic()):
1337+
timeout = 0.01
13431338
if not _cond_wait(self._max_connecting_cond, timeout):
1339+
# Check whether we should continue to wait for the backoff condition.
1340+
if self._backoff and deadline is None or deadline < time.monotonic():
1341+
if self._backoff_connection_time > time.monotonic():
1342+
continue
1343+
break
13441344
# Timed out, notify the next thread to ensure a
13451345
# timeout doesn't consume the condition.
13461346
if self.conns or self._pending < self.max_connecting:

0 commit comments

Comments
 (0)