Resolve auth_store loading race condition (#21794)

* Add lock in auth_store._async_load()

* Python 3.5 does not like assert_called_once()
This commit is contained in:
Jason Hu authored and Paulus Schoutsen committed 2019-03-08 14:50:24 -08:00
1 parent 3ff2d99cd6
commit 3d8673dbf8
5 files changed
+80 -11

No files matched your search

+8
View File
@@ -38,6 +38,7 @@ class AuthStore:
self._perm_lookup = None # type: Optional[PermissionLookup]
self._store = hass.helpers.storage.Store(STORAGE_VERSION, STORAGE_KEY,
private=True)
self._lock = asyncio.Lock()
async def async_get_groups(self) -> List[models.Group]:
"""Retrieve all users."""
@@ -271,6 +272,13 @@ class AuthStore:
self._async_schedule_save()
async def _async_load(self) -> None:
"""Load the users."""
async with self._lock:
if self._users is not None:
return
await self._async_load_task()
async def _async_load_task(self) -> None:
"""Load the users."""
[ent_reg, data] = await asyncio.gather(
self.hass.helpers.entity_registry.async_get_registry(),