aioamqp icon indicating copy to clipboard operation
aioamqp copied to clipboard

No longer handling CancelledError on protocol.run

Open notmeta opened this issue 2 years ago • 0 comments

Since Python 3.8, aioamqp no longer catches and reraises asyncio.CancelledError in protocol.run, leading to delayed manual disconnections.

A fix is just handling both asyncio.CancelledError and Exception like so:

async def run(self):
    while not self.stop_now.is_set():
        try:
            await self.dispatch_frame()
        except exceptions.AmqpClosedConnection as exc:
            logger.info("Close connection")
            self.stop_now.set()

            self._close_channels(exception=exc)
        except (asyncio.CancelledError, Exception):
            logger.exception('error on dispatch')

notmeta avatar May 18 '23 16:05 notmeta