jkeljo / hacs-greeneye-monitor

HACS version of the Home Assistant Core greeneye_monitor component. For beta-testing and faster deployment of changes.
MIT License
6 stars 2 forks source link

GreenEye Monitor component delays restart of Home Assistant after 2024.2.1 #41

Closed bakerkj closed 8 months ago

bakerkj commented 8 months ago

Describe the bug

This custom component seems to blocks/delays a clean restart of Home Assistant. I don't think this happened in 2024.1.x, I skipped 2024.2.0 and it does appear to happen in 2024.2.1.

On restart I see these warnings:

2024-02-10 23:17:19.705 WARNING (MainThread) [homeassistant.core] Shutdown stage 'stop integrations': still running: <Task pending name='Task-100718' coro=<async_setup_entry.<locals>.close_monitors() running at /config/custom_components/greeneye_monitor/__init__.py:148> wait_for=<Future pending cb=[Task.task
_wakeup()]> cb=[set.remove()]>
2024-02-10 23:18:19.708 WARNING (MainThread) [homeassistant.core] Timed out waiting for final writes to complete, the shutdown will continue
2024-02-10 23:18:19.708 WARNING (MainThread) [homeassistant.core] Shutdown stage 'final write': still running: <Task pending name='Task-100718' coro=<async_setup_entry.<locals>.close_monitors() running at /config/custom_components/greeneye_monitor/__init__.py:148> wait_for=<Future pending cb=[Task.task_wakeu
p()]> cb=[set.remove()]>
2024-02-10 23:18:49.711 WARNING (MainThread) [homeassistant.core] Timed out waiting for close event to be processed, the shutdown will continue
2024-02-10 23:18:49.711 WARNING (MainThread) [homeassistant.core] Shutdown stage 'close': still running: <Task pending name='Task-100718' coro=<async_setup_entry.<locals>.close_monitors() running at /config/custom_components/greeneye_monitor/__init__.py:148> wait_for=<Future pending cb=[Task.task_wakeup()]> 
cb=[set.remove()]>

Diagnostics

I'll grab these shortly.

jkeljo commented 8 months ago

Interesting. I'm still on 2023.8, so I've got some upgrading to do. This integration hasn't changed in a while, but it looks like there have been some changes to how HA Core handles shutdown. As far as I can tell locally, it's generally been able to close the server quickly on my instance. I'll upgrade my local install and see if I can repro. If not, I'll see about adding some more logging at least.

jkeljo commented 8 months ago

Well, I can repro in my actual home assistant instance, but not in the dev container that I use to develop this integration. So that's fun.

It looks like the reason this is appearing now is that the behavior of Server.wait_closed changed in Python 3.12 (https://github.com/python/cpython/issues/79033), so it's exposing a bug in the shutdown order in greeneye_monitor. Working to figure that out now.

jkeljo commented 8 months ago

This is fixed in https://github.com/jkeljo/hacs-greeneye-monitor/releases/tag/2024.2.18

bakerkj commented 8 months ago

@jkeljo thanks for the fix!