Fix race condition in Matter unsubscribe method (#103770)

This commit is contained in:
Marcel van der Veldt 2023-11-13 15:42:51 +01:00 committed by GitHub
parent 818bc12f87
commit 0e4186ff8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,7 @@ from __future__ import annotations
from abc import abstractmethod from abc import abstractmethod
from collections.abc import Callable from collections.abc import Callable
from contextlib import suppress
from dataclasses import dataclass from dataclasses import dataclass
import logging import logging
from typing import TYPE_CHECKING, Any, cast from typing import TYPE_CHECKING, Any, cast
@ -110,7 +111,9 @@ class MatterEntity(Entity):
async def async_will_remove_from_hass(self) -> None: async def async_will_remove_from_hass(self) -> None:
"""Run when entity will be removed from hass.""" """Run when entity will be removed from hass."""
for unsub in self._unsubscribes: for unsub in self._unsubscribes:
unsub() with suppress(ValueError):
# suppress ValueError to prevent race conditions
unsub()
@callback @callback
def _on_matter_event(self, event: EventType, data: Any = None) -> None: def _on_matter_event(self, event: EventType, data: Any = None) -> None: