Skip to content

Handle SSLError in TCP comm #8983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2025
Merged
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
19 changes: 10 additions & 9 deletions distributed/comm/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,18 @@ def get_stream_address(comm):

def convert_stream_closed_error(obj, exc):
"""
Re-raise StreamClosedError as CommClosedError.
Re-raise StreamClosedError or SSLError as CommClosedError.
"""
if exc.real_error is not None:
if hasattr(exc, "real_error"):
# The stream was closed because of an underlying OS error
if exc.real_error is None:
raise CommClosedError(f"in {obj}: {exc}") from exc
exc = exc.real_error
if isinstance(exc, ssl.SSLError):
if exc.reason and "UNKNOWN_CA" in exc.reason:
raise FatalCommClosedError(f"in {obj}: {exc.__class__.__name__}: {exc}")
raise CommClosedError(f"in {obj}: {exc.__class__.__name__}: {exc}") from exc
else:
raise CommClosedError(f"in {obj}: {exc}") from exc

if isinstance(exc, ssl.SSLError):
if exc.reason and "UNKNOWN_CA" in exc.reason:
raise FatalCommClosedError(f"in {obj}: {exc.__class__.__name__}: {exc}")
raise CommClosedError(f"in {obj}: {exc.__class__.__name__}: {exc}") from exc


def _close_comm(ref):
Expand Down Expand Up @@ -230,7 +231,7 @@ async def read(self, deserializers=None):
buffer = await read_bytes_rw(stream, buffer_nbytes)
frames.append(buffer)

except StreamClosedError as e:
except (StreamClosedError, SSLError) as e:
self.stream = None
self._closed = True
convert_stream_closed_error(self, e)
Expand Down
Loading