Skip to content

Commit c974d36

Browse files
committed
fix logic
1 parent 70b4113 commit c974d36

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

pymongo/asynchronous/pool.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,13 @@
4949
from pymongo.errors import ( # type:ignore[attr-defined]
5050
AutoReconnect,
5151
ConfigurationError,
52-
ConnectionFailure,
5352
DocumentTooLarge,
5453
ExecutionTimeout,
5554
InvalidOperation,
56-
NetworkTimeout,
5755
NotPrimaryError,
5856
OperationFailure,
5957
PyMongoError,
6058
WaitQueueTimeoutError,
61-
_OperationCancelled,
6259
)
6360
from pymongo.hello import Hello, HelloCompat
6461
from pymongo.helpers_shared import _get_timeout_details, format_timeout_details
@@ -1109,11 +1106,10 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
11091106
async with self.lock:
11101107
self.active_contexts.discard(conn.cancel_context)
11111108
# Enter backoff mode and reconnect on establishment failure.
1112-
if isinstance(e, ConnectionFailure) and not isinstance(
1113-
e, (_OperationCancelled, NetworkTimeout)
1114-
):
1109+
if type(e) == AutoReconnect:
11151110
self._backoff += 1
11161111
# TODO: emit a message about backoff.
1112+
print("backing off", self._backoff) # noqa: T201
11171113
return await self.connect(handler)
11181114
await conn.close_conn(ConnectionClosedReason.ERROR)
11191115
raise

pymongo/synchronous/pool.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,13 @@
4646
from pymongo.errors import ( # type:ignore[attr-defined]
4747
AutoReconnect,
4848
ConfigurationError,
49-
ConnectionFailure,
5049
DocumentTooLarge,
5150
ExecutionTimeout,
5251
InvalidOperation,
53-
NetworkTimeout,
5452
NotPrimaryError,
5553
OperationFailure,
5654
PyMongoError,
5755
WaitQueueTimeoutError,
58-
_OperationCancelled,
5956
)
6057
from pymongo.hello import Hello, HelloCompat
6158
from pymongo.helpers_shared import _get_timeout_details, format_timeout_details
@@ -1105,11 +1102,10 @@ def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> Connect
11051102
with self.lock:
11061103
self.active_contexts.discard(conn.cancel_context)
11071104
# Enter backoff mode and reconnect on establishment failure.
1108-
if isinstance(e, ConnectionFailure) and not isinstance(
1109-
e, (_OperationCancelled, NetworkTimeout)
1110-
):
1105+
if type(e) == AutoReconnect:
11111106
self._backoff += 1
11121107
# TODO: emit a message about backoff.
1108+
print("backing off", self._backoff) # noqa: T201
11131109
return self.connect(handler)
11141110
conn.close_conn(ConnectionClosedReason.ERROR)
11151111
raise

0 commit comments

Comments
 (0)