mosquito / aio-pika

AMQP 0.9 client designed for asyncio and humans.
https://aio-pika.readthedocs.org/
Apache License 2.0
1.18k stars 186 forks source link

Error making robust connection in latest version #543

Closed awarrier99 closed 1 year ago

awarrier99 commented 1 year ago

We have a project that installs the aio_pika package and has been working fine through version 9.0.5. When version 9.0.6 was released, with no code changes on our end, we started receiving an error trying to make use of the connect_robust method:

Task exception was never retrieved
future: <Task finished name='Task-1' coro=<<...>() done, defined at /<...>/venv/lib/python3.11/site-packages/<...>> exception=TypeError("argument of type 'int' is not iterable")>
Traceback (most recent call last):
  File "/<...>/venv/lib/python3.11/site-packages/<...>", line <...>, in <...>
    connection = await connect_robust(host=self.__host,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<...>/venv/lib/python3.11/site-packages/aio_pika/robust_connection.py", line 310, in connect_robust
    connection: AbstractRobustConnection = connection_class(
                                           ^^^^^^^^^^^^^^^^^
  File "/<...>/venv/lib/python3.11/site-packages/aio_pika/robust_connection.py", line 41, in __init__
    super().__init__(url=url, loop=loop, **kwargs)
  File "/<...>/venv/lib/python3.11/site-packages/aio_pika/connection.py", line 64, in __init__
    self.kwargs: Dict[str, Any] = self._parse_kwargs(
                                  ^^^^^^^^^^^^^^^^^^^
  File "/<...>/venv/lib/python3.11/site-packages/aio_pika/connection.py", line 50, in _parse_kwargs
    result[key] = parser(kwargs.get(key, default))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<...>/venv/lib/python3.11/site-packages/aiormq/connection.py", line 113, in parse_timeout
    if "." in v:
       ^^^^^^^^
TypeError: argument of type 'int' is not iterable

Here is the relevant connection code:

connection = await connect_robust(host=self.__host, 
                port=self.__port, 
                login=self.__login, 
                password=self.__password, 
                ssl=True, 
                ssl_options= self.__ssl_options, 
                reconnect_interval=10,
                loop=loop)

For now we have pinned to the previous version, but please let me know if there was a breaking change that might have affected this functionality. Thanks for your hard work, this package has been extremely useful for us!

mosquito commented 1 year ago

Could you please add minimal example with values hidden in self.__host/self.__port etc.

awarrier99 commented 1 year ago

So that connection code was for our cloud-hosted RabbitMQ instance, and unfortunately I can't share the exact values of some of those as they are sensitive for our application. However I was able to also get the same issue running a local RabbitMQ server, version 3.11.15. Here is the connection code for that, with the variable values filled in:

connection = await connect_robust(host='localhost', 
                port='5672', 
                login='guest', 
                password='guest',
                reconnect_interval=10,
                loop=<asyncio event loop>)
brianmedigate commented 1 year ago

it looks like reconnect_interval expects to get a str, because it is parsed using parse_timeout.

https://github.com/mosquito/aio-pika/blob/9fdeca729434c75d892da42a53a9fe382ffa6d42/aio_pika/robust_connection.py#L31

awarrier99 commented 1 year ago

@brianmedigate thanks for figuring that out and @mosquito thanks for the quick fix! Tested with version 9.0.7 and everything is working again