Skip to content

Commit 0e50202

Browse files
committed
PYTHON-5875 - Wrap SSL handshake errors before labeling with overload
1 parent 22c7c40 commit 0e50202

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
@@ -1061,10 +1061,16 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
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 = 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
@@ -1057,10 +1057,16 @@ def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> Connect
10571057
reason=_verbose_connection_error_reason(ConnectionClosedReason.ERROR),
10581058
error=ConnectionClosedReason.ERROR,
10591059
)
1060-
self._handle_connection_error(error)
10611060
if isinstance(error, (IOError, OSError, *SSLErrors)):
10621061
details = _get_timeout_details(self.opts)
1063-
_raise_connection_failure(self.address, error, timeout_details=details)
1062+
# Wrap to AutoReconnect/NetworkTimeout BEFORE labeling so the
1063+
# SystemOverloadedError label lands on the propagated exception.
1064+
try:
1065+
_raise_connection_failure(self.address, error, timeout_details=details)
1066+
except (AutoReconnect, NetworkTimeout) as wrapped:
1067+
self._handle_connection_error(wrapped)
1068+
raise
1069+
self._handle_connection_error(error)
10641070
raise
10651071

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

0 commit comments

Comments
 (0)