Skip to content

Swallowing the CommClosedError when the stream handler closes may remove relevant exception information  #8683

Open
@hendrikmakait

Description

@hendrikmakait

In

except CommClosedError:
closed = True
logger.info(
"Connection to %s has been closed.",
comm.peer_address,
)
break

we always swallow the CommClosedError without even logging it. This can be problematic because we use this error both for the happy and the sad path of stream handler closing. For example, in convert_stream_closed_error (

def convert_stream_closed_error(obj, exc):
"""
Re-raise StreamClosedError as CommClosedError.
"""
if exc.real_error is not None:
# The stream was closed because of an underlying OS error
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
), we may attach relevant exception information to the CommClosedError but will subsequently ignore it in handle_stream.

Ideally, we could differentiate between when stream handler closing is expected and when it's unexpected and log more information in the latter case.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions