juju / python-libjuju

Python library for the Juju API
Apache License 2.0
59 stars 98 forks source link

pylibjuju can't reconnect on python 3.12 #1102

Open gboutry opened 1 day ago

gboutry commented 1 day ago

Description

pylibjuju on python 3.12 fails to reconnect when the websocket closes.

Urgency

Annoying bug in our test suite

Python-libjuju version

3.5.0.0

Juju version

3.5.3

Reproduce / Test

This is because of python 3.11+ -> pylibjuju is passing a coroutine to asyncio.wait, which removed the support for this in 3.11 https://github.com/juju/python-libjuju/blob/7d2107f882e5f7927001004dc2dac74a286740eb/juju/client/connection.py#L659

python 3.11 asyncio: https://github.com/python/cpython/blob/8b275e77d235b0e813f996173fc26eaa3484737c/Lib/asyncio/tasks.py#L425

python 3.10 asyncio: https://github.com/python/cpython/blob/0c5fc27217525c4e40b4064e6979f467540c2fc8/Lib/asyncio/tasks.py#L377

gboutry commented 1 day ago

Logs:

2024-09-18 11:02:15.712533 | ubuntu-noble | 2024-09-18 11:02:15 [ERROR] Task tmp raised an exception: watcher was stopped
2024-09-18 11:02:15.720315 | ubuntu-noble | Traceback (most recent call last):
2024-09-18 11:02:15.720382 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/jasyncio.py", line 41, in _task_result_exp_handler
2024-09-18 11:02:15.720410 | ubuntu-noble |     task.result()
2024-09-18 11:02:15.720435 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/client/facade.py", line 486, in wrapper
2024-09-18 11:02:15.720459 | ubuntu-noble |     reply = await f(*args, **kwargs)
2024-09-18 11:02:15.720482 | ubuntu-noble |             ^^^^^^^^^^^^^^^^^^^^^^^^
2024-09-18 11:02:15.720502 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/client/_client3.py", line 760, in Next
2024-09-18 11:02:15.720521 | ubuntu-noble |     reply = await self.rpc(msg)
2024-09-18 11:02:15.720556 | ubuntu-noble |             ^^^^^^^^^^^^^^^^^^^
2024-09-18 11:02:15.720581 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/client/overrides.py", line 114, in rpc
2024-09-18 11:02:15.720611 | ubuntu-noble |     result = await self.connection.rpc(msg, encoder=TypeEncoder)
2024-09-18 11:02:15.720627 | ubuntu-noble |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-09-18 11:02:15.720645 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/client/connection.py", line 672, in rpc
2024-09-18 11:02:15.744278 | ubuntu-noble |     raise errors.JujuAPIError(result)
2024-09-18 11:02:15.744391 | ubuntu-noble | juju.errors.JujuAPIError: watcher was stopped
2024-09-18 11:02:15.744409 | ubuntu-noble | 2024-09-18 11:02:15 [WARNING] Watcher: watcher stopped, restarting
2024-09-18 11:02:15.744419 | ubuntu-noble | 2024-09-18 11:02:15 [WARNING] RPC: Connection closed, reconnecting
2024-09-18 11:02:15.744441 | ubuntu-noble | 2024-09-18 11:02:15 [ERROR] Task tmp raised an exception: Passing coroutines is forbidden, use tasks explicitly.
2024-09-18 11:02:15.768267 | ubuntu-noble | Traceback (most recent call last):
2024-09-18 11:02:15.768670 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/client/connection.py", line 649, in rpc
2024-09-18 11:02:15.768722 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 630, in send
2024-09-18 11:02:15.768731 | ubuntu-noble |     await self.ensure_open()
2024-09-18 11:02:15.768738 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 931, in ensure_open
2024-09-18 11:02:15.768744 | ubuntu-noble |     raise self.connection_closed_exc()
2024-09-18 11:02:15.768751 | ubuntu-noble | websockets.exceptions.ConnectionClosedOK: received 1005 (no status received [internal]); then sent 1005 (no status received [internal])
2024-09-18 11:02:15.768757 | ubuntu-noble |
2024-09-18 11:02:15.768764 | ubuntu-noble | During handling of the above exception, another exception occurred:
2024-09-18 11:02:15.768770 | ubuntu-noble |
2024-09-18 11:02:15.768788 | ubuntu-noble | Traceback (most recent call last):
2024-09-18 11:02:15.768820 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/jasyncio.py", line 41, in _task_result_exp_handler
2024-09-18 11:02:15.768837 | ubuntu-noble |     task.result()
2024-09-18 11:02:15.768850 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/client/facade.py", line 486, in wrapper
2024-09-18 11:02:15.768859 | ubuntu-noble |     reply = await f(*args, **kwargs)
2024-09-18 11:02:15.768865 | ubuntu-noble |             ^^^^^^^^^^^^^^^^^^^^^^^^
2024-09-18 11:02:15.768872 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/client/_client3.py", line 760, in Next
2024-09-18 11:02:15.768878 | ubuntu-noble |     reply = await self.rpc(msg)
2024-09-18 11:02:15.768884 | ubuntu-noble |             ^^^^^^^^^^^^^^^^^^^
2024-09-18 11:02:15.768890 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/client/overrides.py", line 110, in rpc
2024-09-18 11:02:15.768896 | ubuntu-noble |     result = await client.WatchAll()
2024-09-18 11:02:15.768902 | ubuntu-noble |              ^^^^^^^^^^^^^^^^^^^^^^^
2024-09-18 11:02:15.768909 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/client/facade.py", line 486, in wrapper
2024-09-18 11:02:15.768915 | ubuntu-noble |     reply = await f(*args, **kwargs)
2024-09-18 11:02:15.768921 | ubuntu-noble |             ^^^^^^^^^^^^^^^^^^^^^^^^
2024-09-18 11:02:15.768927 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/client/_client6.py", line 1384, in WatchAll
2024-09-18 11:02:15.768933 | ubuntu-noble |     reply = await self.rpc(msg)
2024-09-18 11:02:15.768939 | ubuntu-noble |             ^^^^^^^^^^^^^^^^^^^
2024-09-18 11:02:15.768945 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/client/facade.py", line 659, in rpc
2024-09-18 11:02:15.768951 | ubuntu-noble |     result = await self.connection.rpc(msg, encoder=TypeEncoder)
2024-09-18 11:02:15.768958 | ubuntu-noble |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-09-18 11:02:15.768964 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/client/connection.py", line 659, in rpc
2024-09-18 11:02:15.768970 | ubuntu-noble |     await jasyncio.wait([self.reconnect()])
2024-09-18 11:02:15.768976 | ubuntu-noble |   File "/usr/lib/python3.12/asyncio/tasks.py", line 461, in wait
2024-09-18 11:02:15.768982 | ubuntu-noble |     raise TypeError("Passing coroutines is forbidden, use tasks explicitly.")
2024-09-18 11:02:15.768988 | ubuntu-noble | TypeError: Passing coroutines is forbidden, use tasks explicitly.
2024-09-18 11:02:15.769001 | ubuntu-noble | /home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/utils.py:191: RuntimeWarning: coroutine 'Connection.reconnect' was never awaited
2024-09-18 11:02:15.773314 | ubuntu-noble |   return task.result()  # may raise exception
2024-09-18 11:02:15.773374 | ubuntu-noble | RuntimeWarning: Enable tracemalloc to get the object allocation traceback
2024-09-18 11:02:15.773398 | ubuntu-noble | 2024-09-18 11:02:15 [ERROR] Error in watcher
2024-09-18 11:02:16.140058 | ubuntu-noble | Traceback (most recent call last):
2024-09-18 11:02:16.140144 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/client/connection.py", line 649, in rpc
2024-09-18 11:02:16.140180 | ubuntu-noble |     await self._ws.send(outgoing)
2024-09-18 11:02:16.140194 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 630, in send
2024-09-18 11:02:16.140206 | ubuntu-noble |     await self.ensure_open()
2024-09-18 11:02:16.140218 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 931, in ensure_open
2024-09-18 11:02:16.140229 | ubuntu-noble |     raise self.connection_closed_exc()
2024-09-18 11:02:16.140239 | ubuntu-noble | websockets.exceptions.ConnectionClosedOK: received 1005 (no status received [internal]); then sent 1005 (no status received [internal])
2024-09-18 11:02:16.140276 | ubuntu-noble |
2024-09-18 11:02:16.140288 | ubuntu-noble | During handling of the above exception, another exception occurred:
2024-09-18 11:02:16.140299 | ubuntu-noble |
2024-09-18 11:02:16.140310 | ubuntu-noble | Traceback (most recent call last):
2024-09-18 11:02:16.140344 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/model.py", line 1206, in _all_watcher
2024-09-18 11:02:16.140374 | ubuntu-noble |     results = await utils.run_with_interrupt(
2024-09-18 11:02:16.140386 | ubuntu-noble |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-09-18 11:02:16.140397 | ubuntu-noble |   File "/home/zuul/src/opendev.org/openstack/sunbeam-charms/.tox/func/lib/python3.12/site-packages/juju/utils.py", line 191, in run_with_interrupt
2024-09-18 11:02:16.140408 | ubuntu-noble |     return task.result()  # may raise exception
2024-09-18 11:02:16.140418 | ubuntu-noble |            ^^^^^^^^^^^^^
2024-09-18 11:02:16.140429 | ubuntu-noble | TypeError: Passing coroutines is forbidden, use tasks explicitly.