juju / python-libjuju

Python library for the Juju API
Apache License 2.0
57 stars 93 forks source link

AttributeError: 'NoneType' object has no attribute 'exception' #1028

Closed freyes closed 3 months ago

freyes commented 4 months ago

Description

libjuju crashes when the shared state watcher was stopped, libjuju tries to handle and fails with the following error: AttributeError: 'NoneType' object has no attribute 'exception'

We are seeing this issue in our CI - https://github.com/openstack-charmers/zaza/actions/runs/7907308186/job/21769045812?pr=608

The full stacktrace is:

  Error: -20 13:19:12 [ERROR] Exception in callback create_task_with_handler.<locals>._task_result_exp_handler(task_name='tmp', logger=None)(<Task finishe...was stopped')>) at /home/runner/work/zaza/zaza/.tox/func-target/lib/python3.10/site-packages/juju/jasyncio.py:53
  handle: <Handle create_task_with_handler.<locals>._task_result_exp_handler(task_name='tmp', logger=None)(<Task finishe...was stopped')>) at /home/runner/work/zaza/zaza/.tox/func-target/lib/python3.10/site-packages/juju/jasyncio.py:53>
  Traceback (most recent call last):
    File "/home/runner/work/zaza/zaza/.tox/func-target/lib/python3.10/site-packages/juju/jasyncio.py", line 55, in _task_result_exp_handler
      task.result()
    File "/home/runner/work/zaza/zaza/.tox/func-target/lib/python3.10/site-packages/juju/client/facade.py", line 486, in wrapper
      reply = await f(*args, **kwargs)
    File "/home/runner/work/zaza/zaza/.tox/func-target/lib/python3.10/site-packages/juju/client/_client1.py", line 315, in Next
      reply = await self.rpc(msg)
    File "/home/runner/work/zaza/zaza/.tox/func-target/lib/python3.10/site-packages/juju/client/overrides.py", line 113, in rpc
      result = await self.connection.rpc(msg, encoder=TypeEncoder)
    File "/home/runner/work/zaza/zaza/.tox/func-target/lib/python3.10/site-packages/juju/client/connection.py", line 635, in rpc
      raise errors.JujuAPIError(result)
  juju.errors.JujuAPIError: shared state watcher was stopped
  During handling of the above exception, another exception occurred:
  Traceback (most recent call last):
    File "/usr/lib/python3.10/asyncio/events.py", line 80, in _run
      self._context.run(self._callback, *self._args)
    File "/home/runner/work/zaza/zaza/.tox/func-target/lib/python3.10/site-packages/juju/jasyncio.py", line 67, in _task_result_exp_handler
      logger.exception("Task %s raised an exception: %s" % (task_name, e))
  AttributeError: 'NoneType' object has no attribute 'exception'

Urgency

Casually reporting

Python-libjuju version

2.9.46.1

Juju version

2.9.46

Reproduce / Test

git clone -b issues/545 https://github.com/freyes/zaza.git
cd zaza
# make sure you have a running juju 2.9 controller
tox -e func-target -- third
cderici commented 4 months ago

So there are two things going on here:

  1. juju.errors.JujuAPIError: shared state watcher was stopped

This is out of scope for pylibjuju, it needs to be investigated on the Juju side.

  1. AttributeError: 'NoneType' object has no attribute 'exception'

This is certainly a bug on pylibjuju, we should be able to trap that. We can fix this here soon 👍

One thing to note here, is that we're starting to actually deprecate the 2.9 support (on Juju, as well as in pylibjuju), we'll have a 2.9.47 release, but after that it'll be only essential security fixes. This particular issue is a small patch, so I'll fix in on 2.9 and forward-port, however, we'll soon be supporting only the 3.x moving forward.

Aflynn50 commented 3 months ago

Fixed with #1035