diff --git a/pymongo/pyopenssl_context.py b/pymongo/pyopenssl_context.py index bfc52df67..83d8f853e 100644 --- a/pymongo/pyopenssl_context.py +++ b/pymongo/pyopenssl_context.py @@ -107,6 +107,11 @@ class _sslConn(_SSL.Connection): try: return call(*args, **kwargs) except BLOCKING_IO_ERRORS as exc: + # Check for closed socket. + if self.fileno() == -1: + if timeout and _time.monotonic() - start > timeout: + raise _socket.timeout("timed out") + raise SSLError("Underlying socket has been closed") if isinstance(exc, _SSL.WantReadError): want_read = True want_write = False