Skip to content
Permalink
Browse files

Ensure storage write consume the data under the lock (#35889)

If two writes trigger at the same time the data would already
be consumed.
  • Loading branch information
bdraco authored and pvizeli committed May 21, 2020
1 parent c88c011 commit ddee8b68c65ba3ec56b43967fbd21af91f40f0e6
Showing with 10 additions and 5 deletions.
  1. +10 −5 homeassistant/helpers/storage.py
@@ -200,14 +200,19 @@ async def _async_callback_final_write(self, _event):

async def _async_handle_write_data(self, *_args):
"""Handle writing the config."""
data = self._data

if "data_func" in data:
data["data"] = data.pop("data_func")()
async with self._write_lock:
if self._data is None:
# Another write already consumed the data
return

self._data = None
data = self._data

if "data_func" in data:
data["data"] = data.pop("data_func")()

self._data = None

async with self._write_lock:
try:
await self.hass.async_add_executor_job(
self._write_data, self.path, data

0 comments on commit ddee8b6

Please sign in to comment.
You can’t perform that action at this time.