Skip to content

Commit 691dd72

Browse files
authored
PYTHON-5875 - Wrap SSL handshake errors before labeling with overload (#2866)
1 parent 3405791 commit 691dd72

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

pymongo/asynchronous/pool.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,10 +1065,16 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
10651065
reason=_verbose_connection_error_reason(ConnectionClosedReason.ERROR),
10661066
error=ConnectionClosedReason.ERROR,
10671067
)
1068-
self._handle_connection_error(error)
10691068
if isinstance(error, (IOError, OSError, *SSLErrors)):
10701069
details = _get_timeout_details(self.opts)
1071-
_raise_connection_failure(self.address, error, timeout_details=details)
1070+
# Wrap to AutoReconnect/NetworkTimeout BEFORE labeling so the
1071+
# SystemOverloadedError label lands on the propagated exception.
1072+
try:
1073+
_raise_connection_failure(self.address, error, timeout_details=details)
1074+
except (AutoReconnect, NetworkTimeout) as wrapped:
1075+
self._handle_connection_error(wrapped)
1076+
raise
1077+
self._handle_connection_error(error)
10721078
raise
10731079

10741080
conn = AsyncConnection(networking_interface, self, self.address, conn_id, self.is_sdam) # type: ignore[arg-type]

pymongo/synchronous/pool.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,10 +1061,16 @@ def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> Connect
10611061
reason=_verbose_connection_error_reason(ConnectionClosedReason.ERROR),
10621062
error=ConnectionClosedReason.ERROR,
10631063
)
1064-
self._handle_connection_error(error)
10651064
if isinstance(error, (IOError, OSError, *SSLErrors)):
10661065
details = _get_timeout_details(self.opts)
1067-
_raise_connection_failure(self.address, error, timeout_details=details)
1066+
# Wrap to AutoReconnect/NetworkTimeout BEFORE labeling so the
1067+
# SystemOverloadedError label lands on the propagated exception.
1068+
try:
1069+
_raise_connection_failure(self.address, error, timeout_details=details)
1070+
except (AutoReconnect, NetworkTimeout) as wrapped:
1071+
self._handle_connection_error(wrapped)
1072+
raise
1073+
self._handle_connection_error(error)
10681074
raise
10691075

10701076
conn = Connection(networking_interface, self, self.address, conn_id, self.is_sdam) # type: ignore[arg-type]

0 commit comments

Comments
 (0)