Polyconseil / aioamqp

AMQP implementation using asyncio
Other
280 stars 88 forks source link

Error callback is called after channel is "legally" closed #117

Open kr41 opened 7 years ago

kr41 commented 7 years ago

I use on_error parameter of aioamqp.connect to pass handler, which reestablish connection when it is accidentally closed. But it is called even after the channel is "legally" closed, which definitely is not an error case. And its exception argument looks weird: ChannelClosed(ChannelClosed(None, None), 'Channel is closed').

Here is the code to reproduce the issue:

import logging
import asyncio
import aioamqp

logger = logging.getLogger(__name__)

def on_error(exc):
    logger.error('Handle error %r', exc)

async def run(loop):
    transport, protocol = await aioamqp.connect(on_error=on_error, loop=loop)
    channel = await protocol.channel()

    logger.info('Close channel')
    await channel.close()
    logger.info('Close protocol')
    await protocol.close()
    logger.info('Close transport')
    transport.close()

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(run(loop=loop))

Here is its output:

DEBUG:asyncio:Using selector: EpollSelector
INFO:aioamqp.protocol:Recv open ok
DEBUG:aioamqp.channel:Channel is open
INFO:__main__:Close channel
INFO:aioamqp.channel:Channel closed
INFO:__main__:Close protocol
INFO:aioamqp.protocol:Recv close ok
INFO:__main__:Close transport
WARNING:aioamqp.protocol:Connection lost exc=None
ERROR:__main__:Handle error ChannelClosed(ChannelClosed(None, None), 'Channel is closed')

Environment: