core: Configuration validation hangs indefinitely

The problem

Clicking on Server Controls -> Check Configuration shows no result. It ends up spinning forever.

Environment

  • Home Assistant Core release with the issue: 0.115.6
  • Last working Home Assistant Core release (if known): -
  • Operating environment (OS/Container/Supervised/Core): Raspbian
  • Integration causing this issue: core issue seen during loading of mobile_app
  • Link to integration documentation on our website:

Problem-relevant configuration.yaml

mobile_app:

Traceback/Error logs

2020-09-30 17:17:21 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/setup.py", line 64, in async_setup_component
    return await task  # type: ignore
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/setup.py", line 158, in _async_setup_component
    await async_process_deps_reqs(hass, config, integration)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/setup.py", line 344, in async_process_deps_reqs
    hass, integration.domain
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/requirements.py", line 97, in async_get_integration_with_requirements
    for dep in deps_to_check
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/requirements.py", line 76, in async_get_integration_with_requirements
    hass, integration.domain, integration.requirements
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/requirements.py", line 122, in async_process_requirements
    if pkg_util.is_installed(req):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/util/package.py", line 54, in is_installed
    return version(req.project_name) in req
  File "/srv/homeassistant/lib/python3.7/site-packages/pkg_resources/__init__.py", line 3078, in __contains__
    return self.specifier.contains(item, prereleases=True)
  File "/srv/homeassistant/lib/python3.7/site-packages/pkg_resources/_vendor/packaging/specifiers.py", line 703, in contains
    item = parse(item)
  File "/srv/homeassistant/lib/python3.7/site-packages/pkg_resources/_vendor/packaging/version.py", line 31, in parse
    return Version(version)
  File "/srv/homeassistant/lib/python3.7/site-packages/pkg_resources/_vendor/packaging/version.py", line 200, in __init__
    match = self._regex.search(version)
TypeError: expected string or bytes-like object

Additional information

The problem was caused by a lock taken during requirements parsing which was not released by the exception handling for the traceback shown above.

I found the problem by tracing through the code in the debugger (debugpy is cool!)

The problematic event lock was taken here:

    event = cache[domain] = asyncio.Event()

In the case that there is an exception thrown as above, that event lock is never released. So when check_config runs, it hangs waiting for the lock.

I was able to reproduce the above traceback by editing hass_nabucasa-0.37.0.dist-info/METADATA and removing the Version field. Obviously that’s not something that would normally happen, but for some reason I did end up with unreadable metadata in the virtualenv. And although I could see the traceback during configuration loading, I didn’t expect there to be a long running lock resulting from that, and didn’t realise it could affect check_config like that.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (2 by maintainers)

Most upvoted comments

Update: by a process of exhaustive elimination, I was able to narrow it down to this entry in my configuration.yaml:

# https://www.home-assistant.io/integrations/bluetooth_tracker/
device_tracker:
  - platform: bluetooth_tracker

When I remove that entry, both the “CHECK CONFIGURATION” and the homeassistant.restart begin working again, without hanging.

If I put those lines back in, anywhere in the configuration.yaml file, it causes the parsing to hang.

What could it be about the device_tracker entry that is causing the problem???

I’m experiencing the bug too on 2022.3.2