mosquito / aiormq

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

RuntimeWarning: coroutine '_ContextManagerMixin.__aexit__' was never awaited #158

Closed rad-pat closed 1 year ago

rad-pat commented 1 year ago

Since upgrading to latest aiormq, we see a number of these warnings in the logs. I enabled tracemalloc in our CI environment to reveal this Traceback. Hope it is useful to identify an issue?

RuntimeWarning: coroutine '_ContextManagerMixin.__aexit__' was never awaited
Coroutine created at (most recent call last)
  File "/home/plaid/src/plaid/plaid/main.py", line 14, in <module>
    uvicorn.run(app, host='0.0.0.0', port=8000, access_log=False, proxy_headers=True, forwarded_allow_ips='*')
  File "/usr/local/lib/python3.11/site-packages/uvicorn/main.py", line 569, in run
    server.run()
  File "/usr/local/lib/python3.11/site-packages/uvicorn/server.py", line 60, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
  File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "/usr/local/lib/python3.11/site-packages/aiormq/connection.py", line 512, in __reader
    async for weight, channel, frame in frame_receiver:
  File "/usr/local/lib/python3.11/site-packages/aiormq/connection.py", line 191, in __anext__
    return await self.get_frame()
  File "/usr/local/lib/python3.11/site-packages/aiormq/connection.py", line 149, in get_frame
    async with countdown.enter_context(self.lock):
  File "/usr/local/lib/python3.11/site-packages/aiormq/tools.py", line 110, in __aexit__
    self.ctx.__aexit__(exc_type, exc_val, exc_tb),

Potentially also useful, I see a Traceback from the early morning in the CI environment where very little is happening overnight, just a daemon task checking in which is publishing a message in RMQ. Somehow an asyncio.TimeoutError has occurred generating a Traceback that looks related to the same code:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiormq/abc.py", line 40, in __inner
    return await self.task
           ^^^^^^^^^^^^^^^
asyncio.exceptions.CancelledError

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

Traceback (most recent call last):
  File "/home/plaid/src/plaid/plaid/core/utility/events.py", line 91, in _publish
    topic_exchange = await channel.get_exchange('amq.topic')
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aio_pika/channel.py", line 277, in get_exchange
    return await self.declare_exchange(name=name, passive=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aio_pika/robust_channel.py", line 145, in declare_exchange
    await super().declare_exchange(
  File "/usr/local/lib/python3.11/site-packages/aio_pika/channel.py", line 250, in declare_exchange
    await exchange.declare(timeout=timeout)
  File "/usr/local/lib/python3.11/site-packages/aio_pika/exchange.py", line 55, in declare
    return await self.channel.exchange_declare(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiormq/channel.py", line 727, in exchange_declare
    return await self.rpc(
           ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiormq/base.py", line 166, in wrap
    return await self.create_task(func(self, *args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiormq/abc.py", line 42, in __inner
    raise self.exception from e
  File "/usr/local/lib/python3.11/asyncio/tasks.py", line 684, in _wrap_awaitable
    return (yield from awaitable.__await__())
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiormq/abc.py", line 42, in __inner
    raise self.exception from e
  File "/usr/local/lib/python3.11/asyncio/tasks.py", line 684, in _wrap_awaitable
    return (yield from awaitable.__await__())
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiormq/abc.py", line 42, in __inner
    raise self.exception from e
  File "/usr/local/lib/python3.11/asyncio/tasks.py", line 684, in _wrap_awaitable
    return (yield from awaitable.__await__())
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiormq/abc.py", line 40, in __inner
    return await self.task
           ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiormq/connection.py", line 512, in __reader
    async for weight, channel, frame in frame_receiver:
  File "/usr/local/lib/python3.11/site-packages/aiormq/connection.py", line 191, in __anext__
    return await self.get_frame()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiormq/connection.py", line 149, in get_frame
    async with countdown.enter_context(self.lock):
  File "/usr/local/lib/python3.11/site-packages/aiormq/tools.py", line 109, in __aexit__
    return await self.countdown(
                 ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiormq/tools.py", line 86, in __call__
    timeout = self.get_timeout()
              ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiormq/tools.py", line 81, in get_timeout
    raise asyncio.TimeoutError
TimeoutError