Skip to content

Commit 320cb54

Browse files
committed
fix pool backoff
1 parent 0997248 commit 320cb54

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

pymongo/asynchronous/pool.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,13 +1105,12 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
11051105
except BaseException as e:
11061106
async with self.lock:
11071107
self.active_contexts.discard(conn.cancel_context)
1108-
# Enter backoff mode and reconnect on establishment failure.
1108+
# Handle system overload condition. When the base AutoReconnect is
1109+
# raised and we are not an sdam pool, add to backoff and add the
1110+
# appropriate error label.
11091111
if not self.is_sdam and type(e) == AutoReconnect:
1110-
await conn.close_conn(ConnectionClosedReason.ERROR)
11111112
self._backoff += 1
1112-
# TODO: emit a message about backoff.
1113-
print("backing off", self._backoff) # noqa: T201
1114-
return await self.connect(handler)
1113+
e._add_error_label("SystemOverloaded")
11151114
await conn.close_conn(ConnectionClosedReason.ERROR)
11161115
raise
11171116

pymongo/synchronous/pool.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,13 +1101,12 @@ def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> Connect
11011101
except BaseException as e:
11021102
with self.lock:
11031103
self.active_contexts.discard(conn.cancel_context)
1104-
# Enter backoff mode and reconnect on establishment failure.
1104+
# Handle system overload condition. When the base AutoReconnect is
1105+
# raised and we are not an sdam pool, add to backoff and add the
1106+
# appropriate error label.
11051107
if not self.is_sdam and type(e) == AutoReconnect:
1106-
conn.close_conn(ConnectionClosedReason.ERROR)
11071108
self._backoff += 1
1108-
# TODO: emit a message about backoff.
1109-
print("backing off", self._backoff) # noqa: T201
1110-
return self.connect(handler)
1109+
e._add_error_label("SystemOverloaded")
11111110
conn.close_conn(ConnectionClosedReason.ERROR)
11121111
raise
11131112

0 commit comments

Comments
 (0)