Skip to content

Commit 6d8369f

Browse files
committed
wip
1 parent 5ef7656 commit 6d8369f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pymongo/asynchronous/pool.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,14 @@ 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
13161318
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
13171324
# Timed out, notify the next thread to ensure a
13181325
# timeout doesn't consume the condition.
13191326
if self.requests < self.max_pool_size:
@@ -1355,7 +1362,7 @@ async def _get_conn(
13551362
conn = None
13561363
continue
13571364
# See if we need to wait for the backoff period.
1358-
elif self._backoff and (self._backoff_connection_time < time.monotonic()):
1365+
elif self._backoff and (self._backoff_connection_time > time.monotonic()):
13591366
continue
13601367
else: # We need to create a new connection
13611368
try:

pymongo/synchronous/pool.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,14 @@ 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
13121314
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
13131320
# Timed out, notify the next thread to ensure a
13141321
# timeout doesn't consume the condition.
13151322
if self.requests < self.max_pool_size:
@@ -1351,7 +1358,7 @@ def _get_conn(
13511358
conn = None
13521359
continue
13531360
# See if we need to wait for the backoff period.
1354-
elif self._backoff and (self._backoff_connection_time < time.monotonic()):
1361+
elif self._backoff and (self._backoff_connection_time > time.monotonic()):
13551362
continue
13561363
else: # We need to create a new connection
13571364
try:

0 commit comments

Comments
 (0)