|
40 | 40 | from pymongo.pool_options import PoolOptions |
41 | 41 | from pymongo.ssl_support import HAS_SNI, PYSSLError, SSLError |
42 | 42 |
|
| 43 | +SSLErrors = (PYSSLError, SSLError) |
43 | 44 | if TYPE_CHECKING: |
44 | 45 | from pymongo.pyopenssl_context import _sslConn |
45 | 46 | from pymongo.typings import _Address |
@@ -138,7 +139,7 @@ def _raise_connection_failure( |
138 | 139 | msg += format_timeout_details(timeout_details) |
139 | 140 | if isinstance(error, socket.timeout): |
140 | 141 | raise NetworkTimeout(msg) from error |
141 | | - elif isinstance(error, (SSLError, PYSSLError)) and "timed out" in str(error): |
| 142 | + elif isinstance(error, SSLErrors) and "timed out" in str(error): |
142 | 143 | # Eventlet does not distinguish TLS network timeouts from other |
143 | 144 | # SSLErrors (https://github.com/eventlet/eventlet/issues/692). |
144 | 145 | # Luckily, we can work around this limitation because the phrase |
@@ -293,7 +294,7 @@ async def _async_configured_socket( |
293 | 294 | # Raise _CertificateError directly like we do after match_hostname |
294 | 295 | # below. |
295 | 296 | raise |
296 | | - except (OSError, SSLError, PYSSLError) as exc: |
| 297 | + except (OSError, *SSLErrors) as exc: |
297 | 298 | sock.close() |
298 | 299 | # We raise AutoReconnect for transient and permanent SSL handshake |
299 | 300 | # failures alike. Permanent handshake failures, like protocol |
@@ -349,7 +350,7 @@ async def _configured_protocol_interface( |
349 | 350 | # Raise _CertificateError directly like we do after match_hostname |
350 | 351 | # below. |
351 | 352 | raise |
352 | | - except (OSError, SSLError, PYSSLError) as exc: |
| 353 | + except (OSError, *SSLErrors) as exc: |
353 | 354 | # We raise AutoReconnect for transient and permanent SSL handshake |
354 | 355 | # failures alike. Permanent handshake failures, like protocol |
355 | 356 | # mismatch, will be turned into ServerSelectionTimeoutErrors later. |
@@ -467,7 +468,7 @@ def _configured_socket(address: _Address, options: PoolOptions) -> Union[socket. |
467 | 468 | # Raise _CertificateError directly like we do after match_hostname |
468 | 469 | # below. |
469 | 470 | raise |
470 | | - except (OSError, SSLError, PYSSLError) as exc: |
| 471 | + except (OSError, *SSLErrors) as exc: |
471 | 472 | sock.close() |
472 | 473 | # We raise AutoReconnect for transient and permanent SSL handshake |
473 | 474 | # failures alike. Permanent handshake failures, like protocol |
@@ -516,7 +517,7 @@ def _configured_socket_interface(address: _Address, options: PoolOptions) -> Net |
516 | 517 | # Raise _CertificateError directly like we do after match_hostname |
517 | 518 | # below. |
518 | 519 | raise |
519 | | - except (OSError, SSLError, PYSSLError) as exc: |
| 520 | + except (OSError, *SSLErrors) as exc: |
520 | 521 | sock.close() |
521 | 522 | # We raise AutoReconnect for transient and permanent SSL handshake |
522 | 523 | # failures alike. Permanent handshake failures, like protocol |
|
0 commit comments