Skip to content

Commit a7324e5

Browse files
committed
make combined error type
1 parent 56c9662 commit a7324e5

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

pymongo/pool_shared.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from pymongo.pool_options import PoolOptions
4141
from pymongo.ssl_support import HAS_SNI, PYSSLError, SSLError
4242

43+
SSLErrors = (PYSSLError, SSLError)
4344
if TYPE_CHECKING:
4445
from pymongo.pyopenssl_context import _sslConn
4546
from pymongo.typings import _Address
@@ -138,7 +139,7 @@ def _raise_connection_failure(
138139
msg += format_timeout_details(timeout_details)
139140
if isinstance(error, socket.timeout):
140141
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):
142143
# Eventlet does not distinguish TLS network timeouts from other
143144
# SSLErrors (https://github.com/eventlet/eventlet/issues/692).
144145
# Luckily, we can work around this limitation because the phrase
@@ -293,7 +294,7 @@ async def _async_configured_socket(
293294
# Raise _CertificateError directly like we do after match_hostname
294295
# below.
295296
raise
296-
except (OSError, SSLError, PYSSLError) as exc:
297+
except (OSError, *SSLErrors) as exc:
297298
sock.close()
298299
# We raise AutoReconnect for transient and permanent SSL handshake
299300
# failures alike. Permanent handshake failures, like protocol
@@ -349,7 +350,7 @@ async def _configured_protocol_interface(
349350
# Raise _CertificateError directly like we do after match_hostname
350351
# below.
351352
raise
352-
except (OSError, SSLError, PYSSLError) as exc:
353+
except (OSError, *SSLErrors) as exc:
353354
# We raise AutoReconnect for transient and permanent SSL handshake
354355
# failures alike. Permanent handshake failures, like protocol
355356
# mismatch, will be turned into ServerSelectionTimeoutErrors later.
@@ -467,7 +468,7 @@ def _configured_socket(address: _Address, options: PoolOptions) -> Union[socket.
467468
# Raise _CertificateError directly like we do after match_hostname
468469
# below.
469470
raise
470-
except (OSError, SSLError, PYSSLError) as exc:
471+
except (OSError, *SSLErrors) as exc:
471472
sock.close()
472473
# We raise AutoReconnect for transient and permanent SSL handshake
473474
# failures alike. Permanent handshake failures, like protocol
@@ -516,7 +517,7 @@ def _configured_socket_interface(address: _Address, options: PoolOptions) -> Net
516517
# Raise _CertificateError directly like we do after match_hostname
517518
# below.
518519
raise
519-
except (OSError, SSLError, PYSSLError) as exc:
520+
except (OSError, *SSLErrors) as exc:
520521
sock.close()
521522
# We raise AutoReconnect for transient and permanent SSL handshake
522523
# failures alike. Permanent handshake failures, like protocol

0 commit comments

Comments
 (0)