Skip to content

Commit

Permalink
Handle ssl error in TCP comm (#8983)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtomlinson authored Jan 10, 2025
1 parent 0657de2 commit bcdbabe
Showing 1 changed file with 10 additions and 9 deletions.
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

0 comments on commit bcdbabe

Please sign in to comment.