Skip to content

Commit 09fc66d

Browse files
committed
use AutoReconnect
1 parent 845f17a commit 09fc66d

File tree

3 files changed

+63
-45
lines changed

3 files changed

+63
-45
lines changed

pymongo/asynchronous/pool.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,11 +1102,12 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
11021102

11031103
await conn.authenticate()
11041104
# Catch KeyboardInterrupt, CancelledError, etc. and cleanup.
1105-
except BaseException:
1105+
except BaseException as e:
11061106
async with self.lock:
11071107
self.active_contexts.discard(conn.cancel_context)
11081108
# Enter backoff mode and reconnect on establishment failure.
1109-
if conn.conn_closed():
1109+
if type(e) == AutoReconnect:
1110+
await conn.close_conn(ConnectionClosedReason.ERROR)
11101111
self._backoff += 1
11111112
# TODO: emit a message about backoff.
11121113
print("backing off", self._backoff) # noqa: T201

pymongo/synchronous/pool.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,11 +1098,12 @@ def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> Connect
10981098

10991099
conn.authenticate()
11001100
# Catch KeyboardInterrupt, CancelledError, etc. and cleanup.
1101-
except BaseException:
1101+
except BaseException as e:
11021102
with self.lock:
11031103
self.active_contexts.discard(conn.cancel_context)
11041104
# Enter backoff mode and reconnect on establishment failure.
1105-
if conn.conn_closed():
1105+
if type(e) == AutoReconnect:
1106+
conn.close_conn(ConnectionClosedReason.ERROR)
11061107
self._backoff += 1
11071108
# TODO: emit a message about backoff.
11081109
print("backing off", self._backoff) # noqa: T201

0 commit comments

Comments
 (0)