Issue Description:
we are getting more and more reports of users that their localStorage data is suddenly deleted.
Example from log:
in Background.html.199.log we successfully write a localStorage entry @ 2021-05-01 21:03:31,564
in Background.html.200.log we compare the value previously stored with a value that we keep in a file in the filesystem @ 2021-05-01 21:45:54,926.
as you can see, data is not in sync:
time from fileSystem(time from localStorage): 1619874211564 (1619858021298)
Can you reproduce it (exact steps to reproduce): No
Impact for my app: ~4K DAU, that experience full data loss.
Do you currently have a workaround? yes. we have implemented a mechanism that backs up the users’s storage to the filesystem if we identify the said corruption
Logs:
ow_440fb7b8-a200-466e-84c7-a6c086798e89-2021-05-04-01-37-28.zip (3.4 MB)
1 Like
We are not able to reproduce it yet, but we are still discussing it. I will let you know.
Thanks
1 Like
@shir.brass Hi,
So we internally discussed it. And, from your description, we agreed that the description of the issue is not clear enough - we can’t understand what and how exactly you are doing as we are not familiar with the code.
In general - if you find yourselves writing entire modules around the integrity of localStorage, it’s better to stop using it.
In particular - try to search your logs for the value: 1619858021298 - maybe it is a previous value.
If you find it in your logs - then it probably means there is no corruption of the localStorage - it might mean that your last update (1619874211564) wasn’t flushed to disk.
If it wasn’t flushed to disk - maybe you should wait a bit longer between writing to localStorage and shutting down your app.
Thanks.
1 Like
After reading your comment, I’ve dug further into localStorage flushing and you might have cracked the case: 510133 - chromium - An open-source project to help move the web forward. - Monorail
from Chromium’s documentation, calling localStorage.setItem
is synchronius, but the actual flushing to disk is asynchronous, and there’s no wait to force flush nor await for the flush to happen.
I believe we’ll start with waiting a bit longer before closing the app and I’ll ping you if there’s any followup needed
1 Like