mosquito / aiormq

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

yarl 1.9.5 causes AMQPInternalError #203

Closed ofekashery closed 4 weeks ago

ofekashery commented 4 weeks ago

On August 30, 2024, yarl released version 1.9.5. On this version, they introduced breaking changes for parsing the %2F char in path, which is frequently used by vhosts in the AMQP connection strings.

url = yarl.URL("amqp://localhost/%2f")
print(url.path)
# Yarl v1.9.4 -> `//` -> self.vhost = '/' 
# Yarl v1.9.5 -> `/%2F` -> self.vhost = '%2F'

This bug broke our critical production system, which relied on %2F as the vhost and led into protocol issues. I have updated the yarn developers here and will wait for their reply. Here is the affected logs from aiormq:

Traceback (most recent call last):
  File "aiormq/abc.py", line 44, 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 "example.py", line 21, in <module>
    asyncio.run(main())
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "example.py", line 15, in main
    connection = await aiormq.connect("amqp://****:****@localhost/%2F")
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "aiormq/connection.py", line 982, in connect
    await connection.connect(client_properties or {})
  File "aiormq/base.py", line 164, in wrap
    return await self.create_task(func(self, *args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "aiormq/abc.py", line 46, in __inner
    raise self._exception from e
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/tasks.py", line 684, in _wrap_awaitable
    return (yield from awaitable.__await__())
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "aiormq/abc.py", line 46, in __inner
    raise self._exception from e
  File "aiormq/connection.py", line 550, in connect
    frame = await self._rpc(
            ^^^^^^^^^^^^^^^^
  File "aiormq/connection.py", line 463, in _rpc
    raise AMQPInternalError(
pamqp.exceptions.AMQPInternalError: ("one of ['Connection.OpenOk']", <Connection.Close object at 0x105bf4ef0>)
ofekashery commented 4 weeks ago

Suggested a fix in #202.