benjamin-hodgson / asynqp

An AMQP library for asyncio
MIT License
84 stars 29 forks source link

Connection can not close after graceful server restart #35

Closed TarasLevelUp closed 9 years ago

TarasLevelUp commented 9 years ago

How to reproduce: 1) Run this script

import asyncio
import asynqp

@asyncio.coroutine
def main_coro(loop):
    # connect to the RabbitMQ broker
    connection = yield from asynqp.connect(
        'localhost', 5672, username='guest', password='guest')

    # Open a communications channel
    channel = yield from connection.open_channel()

    disconnected_waiter = asyncio.Future()

    try:
        # Will never finish
        yield from disconnected_waiter
    except asyncio.CancelledError:
        # Maybe we got KeyboardInterupt? Try to gracefully close everything
        yield from channel.close()
        yield from connection.close()

def main():
    loop = asyncio.get_event_loop()
    main_task = asyncio.async(main_coro(loop))
    try:
        loop.run_until_complete(main_task)
    except KeyboardInterrupt:
        main_task.cancel()
        loop.run_until_complete(main_task)

if __name__ == "__main__":
    main()

2) Close rabbitmq by ctl command rabbitmqctl stop (separate terminal) 3) Close script by ctrl+C Expected result: Script closes Real result: Script block on connection.close() call, as it can't receive ConnectionCloseOk frame.

TarasLevelUp commented 9 years ago

I think, this one's closed