Skip to content

Commit 5e64aa9

Browse files
committed
fix race condition
1 parent 24542c9 commit 5e64aa9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

pymongo/asynchronous/pool.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,9 @@ async def _get_conn(
13371337
self._raise_if_not_ready(checkout_started_time, emit_event=False)
13381338
while not (self.conns or self._pending < self.max_connecting):
13391339
timeout = deadline - time.monotonic() if deadline else None
1340-
if self._backoff and (self._backoff_connection_time > time.monotonic()):
1340+
if self._backoff:
1341+
if self._backoff_connection_time < time.monotonic():
1342+
break
13411343
timeout = 0.01
13421344
if not await _async_cond_wait(self._max_connecting_cond, timeout):
13431345
# Check whether we should continue to wait for the backoff condition.

pymongo/synchronous/pool.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,9 @@ def _get_conn(
13331333
self._raise_if_not_ready(checkout_started_time, emit_event=False)
13341334
while not (self.conns or self._pending < self.max_connecting):
13351335
timeout = deadline - time.monotonic() if deadline else None
1336-
if self._backoff and (self._backoff_connection_time > time.monotonic()):
1336+
if self._backoff:
1337+
if self._backoff_connection_time < time.monotonic():
1338+
break
13371339
timeout = 0.01
13381340
if not _cond_wait(self._max_connecting_cond, timeout):
13391341
# Check whether we should continue to wait for the backoff condition.

0 commit comments

Comments
 (0)