@@ -129,17 +129,18 @@ def get_stream_address(comm):
129
129
130
130
def convert_stream_closed_error (obj , exc ):
131
131
"""
132
- Re-raise StreamClosedError as CommClosedError.
132
+ Re-raise StreamClosedError or SSLError as CommClosedError.
133
133
"""
134
- if exc . real_error is not None :
134
+ if hasattr ( exc , "real_error" ) :
135
135
# The stream was closed because of an underlying OS error
136
+ if exc .real_error is None :
137
+ raise CommClosedError (f"in { obj } : { exc } " ) from exc
136
138
exc = exc .real_error
137
- if isinstance (exc , ssl .SSLError ):
138
- if exc .reason and "UNKNOWN_CA" in exc .reason :
139
- raise FatalCommClosedError (f"in { obj } : { exc .__class__ .__name__ } : { exc } " )
140
- raise CommClosedError (f"in { obj } : { exc .__class__ .__name__ } : { exc } " ) from exc
141
- else :
142
- raise CommClosedError (f"in { obj } : { exc } " ) from exc
139
+
140
+ if isinstance (exc , ssl .SSLError ):
141
+ if exc .reason and "UNKNOWN_CA" in exc .reason :
142
+ raise FatalCommClosedError (f"in { obj } : { exc .__class__ .__name__ } : { exc } " )
143
+ raise CommClosedError (f"in { obj } : { exc .__class__ .__name__ } : { exc } " ) from exc
143
144
144
145
145
146
def _close_comm (ref ):
@@ -230,7 +231,7 @@ async def read(self, deserializers=None):
230
231
buffer = await read_bytes_rw (stream , buffer_nbytes )
231
232
frames .append (buffer )
232
233
233
- except StreamClosedError as e :
234
+ except ( StreamClosedError , SSLError ) as e :
234
235
self .stream = None
235
236
self ._closed = True
236
237
convert_stream_closed_error (self , e )
0 commit comments