Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pymongo/asynchronous/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,10 +1061,16 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
reason=_verbose_connection_error_reason(ConnectionClosedReason.ERROR),
error=ConnectionClosedReason.ERROR,
)
self._handle_connection_error(error)
if isinstance(error, (IOError, OSError, *SSLErrors)):
details = _get_timeout_details(self.opts)
_raise_connection_failure(self.address, error, timeout_details=details)
# Wrap to AutoReconnect/NetworkTimeout BEFORE labeling so the
# SystemOverloadedError label lands on the propagated exception.
try:
_raise_connection_failure(self.address, error, timeout_details=details)
except (AutoReconnect, NetworkTimeout) as wrapped:
self._handle_connection_error(wrapped)
raise
Comment thread
NoahStapp marked this conversation as resolved.
self._handle_connection_error(error)
Comment on lines 1064 to +1073

@NoahStapp NoahStapp Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the relevant part of the CMAP spec, the only types of establishment errors that MUST be excluded from having the backpressure labels applied are the following:

  1. DNS lookup failures: excluded by the socket.gaierror check in _handle_connection_error.
  2. Non-I/O TLS errors (certificate validation, hostname mismatch failures): excluded the _CertificateError, SSLErrors check in `_handle_connection_errors.
  3. SOCKS5 errors: PyMongo does not currently support SOCKS5.

This change then correctly addresses a bug in the driver where errors that MUST be labeled as possible overload errors are not.

raise

conn = AsyncConnection(networking_interface, self, self.address, conn_id, self.is_sdam) # type: ignore[arg-type]
Expand Down
10 changes: 8 additions & 2 deletions pymongo/synchronous/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,10 +1057,16 @@ def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> Connect
reason=_verbose_connection_error_reason(ConnectionClosedReason.ERROR),
error=ConnectionClosedReason.ERROR,
)
self._handle_connection_error(error)
if isinstance(error, (IOError, OSError, *SSLErrors)):
details = _get_timeout_details(self.opts)
_raise_connection_failure(self.address, error, timeout_details=details)
# Wrap to AutoReconnect/NetworkTimeout BEFORE labeling so the
# SystemOverloadedError label lands on the propagated exception.
try:
_raise_connection_failure(self.address, error, timeout_details=details)
except (AutoReconnect, NetworkTimeout) as wrapped:
self._handle_connection_error(wrapped)
raise
self._handle_connection_error(error)
raise

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