Skip to content

Connection class disconnects on BaseException #2103

Closed
@kristjanvalur

Description

@kristjanvalur

Version: 4.2.2

Platform: Windows 11

Description: The methods send_packed_command and read_response on the asyncio.connection.Connection class
have exception handlers which catch BaseException and call self.disconnect() before re-raising.

This is rather unfortunate, because it makes it impossible to use an outer Timeout around redis methods. For example, the following pattern fails:

async def get_next_message_or_None():
        async with async_timeout.timeout(0.9) as self.timeout_manager:
                # blocking method to return messages
                async for message in self.pubsub.listen():
                        return message

This is because internally, the timeout will raise a CancelledError in the task. This is a base exception and isn't converted into a TimeoutError until higher in the call stack.

Generally, BaseExceptions should not be caught. In this case, it would be prudent to change this to catch Exception instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions