Skip homekit_controller polls when system is overloaded and still trying to process the previous one (#25968)

* Skip async_update if there are signs of backpressure

* Black

* Only warn once

* Log on recovery

* Formatting fix
This commit is contained in:
Jc2k 2019-08-18 05:14:46 +01:00 committed by Paulus Schoutsen
parent 8da1879599
commit 2bd832cd7a

View file

@ -103,6 +103,10 @@ class HKDevice:
# this method.
self._polling_interval_remover = None
# Never allow concurrent polling of the same accessory or bridge
self._polling_lock = asyncio.Lock()
self._polling_lock_warned = False
def add_pollable_characteristics(self, characteristics):
"""Add (aid, iid) pairs that we need to poll."""
self.pollable_characteristics.extend(characteristics)
@ -247,6 +251,21 @@ class HKDevice:
_LOGGER.debug("HomeKit connection not polling any characteristics.")
return
if self._polling_lock.locked():
if not self._polling_lock_warned:
_LOGGER.warning(
"HomeKit controller update skipped as previous poll still in flight"
)
self._polling_lock_warned = True
return
if self._polling_lock_warned:
_LOGGER.info(
"HomeKit controller no longer detecting back pressure - not skipping poll"
)
self._polling_lock_warned = False
async with self._polling_lock:
_LOGGER.debug("Starting HomeKit controller update")
try: