mosquito / aiormq

Pure python AMQP 0.9.1 asynchronous client library
Other
268 stars 58 forks source link

Future exception was never retrieved #177

Open levsh opened 1 year ago

levsh commented 1 year ago

Hi! I have such error on force connection close. To reproduce bug run this example code and twice close connection via RabbitMQ management plugin

import asyncio
import aiormq

async def main():
    for _ in range(2):
        try:
            connection = await aiormq.connect("amqp://guest:guest@your_rabbitmq_ip/")
            channel = await connection.channel()
            await channel.queue_declare("test")

            while True:
                await channel.basic_publish(b"0", routing_key="test")
                await asyncio.sleep(0.01)

        except (BaseException, Exception) as e:
            print(f"EXCEPTION: {e}")

if __name__ == "__main__":
    asyncio.run(main())

Output

Unexpected connection close from remote "amqp://guest:******@172.18.0.2:5672/", Connection.Close(reply_code=320, reply_text='CONNECTION_FORCED - Closed via management plugin')
NoneType: None
EXCEPTION: [Errno 320] CONNECTION_FORCED - Closed via management plugin
Unexpected connection close from remote "amqp://guest:******@172.18.0.2:5672/", Connection.Close(reply_code=320, reply_text='CONNECTION_FORCED - Closed via management plugin')
NoneType: None
EXCEPTION: [Errno 320] CONNECTION_FORCED - Closed via management plugin
Future exception was never retrieved
future: <Future finished exception=<ConnectionClosed: (320, 'CONNECTION_FORCED - Closed via management plugin')> created at /home/vagrant/.pyenv/versions/3.11.2/lib/python3.11/asyncio/base_events.py:427>
source_traceback: Object created at (most recent call last):
  File "/vagrant/dev/.../test.py", line 22, in <module>
    asyncio.run(main())
  File "/home/vagrant/.pyenv/versions/3.11.2/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
  File "/home/vagrant/.pyenv/versions/3.11.2/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "/home/vagrant/.pyenv/versions/3.11.2/lib/python3.11/asyncio/base_events.py", line 640, in run_until_complete
    self.run_forever()
  File "/home/vagrant/.pyenv/versions/3.11.2/lib/python3.11/asyncio/base_events.py", line 607, in run_forever
    self._run_once()
  File "/home/vagrant/.pyenv/versions/3.11.2/lib/python3.11/asyncio/base_events.py", line 1914, in _run_once
    handle._run()
  File "/home/vagrant/.pyenv/versions/3.11.2/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/vagrant/dev/.../test.py", line 14, in main
    await channel.basic_publish(b"0", routing_key="test")
  File "/home/vagrant/.local/share/virtualenvs/.../lib/python3.11/site-packages/aiormq/channel.py", line 662, in basic_publish
    ] = self.create_future()
  File "/home/vagrant/.local/share/virtualenvs/.../lib/python3.11/site-packages/aiormq/base.py", line 115, in create_future
    return self.__future_store.create_future()
  File "/home/vagrant/.local/share/virtualenvs/.../lib/python3.11/site-packages/aiormq/base.py", line 72, in create_future
    future = self.loop.create_future()
  File "/home/vagrant/.pyenv/versions/3.11.2/lib/python3.11/asyncio/base_events.py", line 427, in create_future
    return futures.Future(loop=self)
Traceback (most recent call last):
  File "/home/vagrant/.local/share/virtualenvs/.../lib/python3.11/site-packages/aiormq/abc.py", line 44, in __inner
    return await self.task
           ^^^^^^^^^^^^^^^
  File "/home/vagrant/.local/share/virtualenvs/.../lib/python3.11/site-packages/aiormq/connection.py", line 663, in __heartbeat
    await asyncio.sleep(heartbeat_timeout)
  File "/home/vagrant/.pyenv/versions/3.11.2/lib/python3.11/asyncio/tasks.py", line 639, in sleep
    return await future
           ^^^^^^^^^^^^
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/vagrant/.pyenv/versions/3.11.2/lib/python3.11/asyncio/tasks.py", line 684, in _wrap_awaitable
    return (yield from awaitable.__await__())
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vagrant/.local/share/virtualenvs/.../lib/python3.11/site-packages/aiormq/abc.py", line 46, in __inner
    raise self._exception from e
  File "/vagrant/dev/.../test.py", line 14, in main
    await channel.basic_publish(b"0", routing_key="test")
  File "/home/vagrant/.local/share/virtualenvs/.../lib/python3.11/site-packages/aiormq/channel.py", line 691, in basic_publish
    await drain_future
  File "/home/vagrant/.pyenv/versions/3.11.2/lib/python3.11/asyncio/tasks.py", line 684, in _wrap_awaitable
    return (yield from awaitable.__await__())
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vagrant/.local/share/virtualenvs/arrlio-IWREsTmp/lib/python3.11/site-packages/aiormq/abc.py", line 44, in __inner
    return await self.task
           ^^^^^^^^^^^^^^^
  File "/home/vagrant/.local/share/virtualenvs/.../lib/python3.11/site-packages/aiormq/connection.py", line 624, in __reader
    await handler(frame)
  File "/home/vagrant/.local/share/virtualenvs/.../lib/python3.11/site-packages/aiormq/connection.py", line 557, in __handle_close
    raise exception
aiormq.exceptions.ConnectionClosed: [Errno 320] CONNECTION_FORCED - Closed via management plugin

python 3.11.2 aiormq 6.7.4

Thank you!