home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.03k stars 29.68k forks source link

Stacktrace from `entity_registry.py` on startup, web server never starts #115961

Closed chl33 closed 1 month ago

chl33 commented 4 months ago

The problem

The home assistant web interface stopped working, and restarting the system and rebooting the computer doesn't fix the problem. I see a stacktrace in the log file when I ssh into the system. Before that, less than a day ago, I saw the web interface stop once and it was restored after restarting the HAOS VM. The observer URL always reports that everything is fine.

What version of Home Assistant Core has the issue?

2024.4.3

What was the last working version of Home Assistant Core?

2024.4.2

What type of installation are you running?

Home Assistant OS

I'm running it on a NUC under Proxmox.

Integration causing the issue

No response

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

This is the stacktrace I see in the log file. There are no further entries in the log after this.``

2024-04-22 07:35:10.848 ERROR (MainThread) [root] Uncaught exception
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 222, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 210, in main
    exit_code = runner.run(runtime_conf)
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/runner.py", line 189, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 685, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/runner.py", line 155, in setup_and_run_hass
    hass = await bootstrap.async_setup_hass(runtime_config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/bootstrap.py", line 281, in async_setup_hass
    await async_from_config_dict(config_dict, hass) is not None
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/bootstrap.py", line 403, in async_from_config_dict
    await async_load_base_functionality(hass)
  File "/usr/src/homeassistant/homeassistant/bootstrap.py", line 375, in async_load_base_functionality
    await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_registry.py", line 1321, in async_load
    await hass.data[DATA_REGISTRY].async_load()
  File "/usr/src/homeassistant/homeassistant/helpers/entity_registry.py", line 1213, in async_load
    original_name=entity["original_name"],
                  ~~~~~~^^^^^^^^^^^^^^^^^
KeyError: 'original_name'

Additional information

I've built a bunch of devices using MQTT and HA discovery with my own software, and some (especially the older ones) could easily have made entries in the discovery subtree which cause trouble.

Custom integrations installed

chl33 commented 4 months ago

(I updated the stacktrace from the original post, since it was incomplete, and added a list of custom integrations installed.)

chl33 commented 4 months ago

I deleted my MQTT homeassistant/ auto-discovery messages to see whether it would allow HA to startup properly, but it seems to crash before the mqtt integration starts. I assume I probably need to do some kind of database repair??

bdraco commented 4 months ago

It looks like your entity registry is corrupt

check the contents of /config/.storage/core.entity_registry

r2kch commented 4 months ago

Had the same issue today, after an power outage. Had to rollback to 2024.4.2 and now everything is working smoothly.

chl33 commented 4 months ago

Thanks. I have had my VM crash a few times before this problem happened (VM with 8GB running out of memory possibly, I'm not sure why) so maybe that left my system in a bad state. If this happens again, I'll look in the directory you suggested. I reverted to a snapshot from a day previously and the stacktrace stopped happening. I have had the VM crash a couple times again, so I suppose I need to figure out how to make it more robust somehow.

issue-triage-workflows[bot] commented 1 month ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.