ammarahm-ed / react-native-mmkv-storage

An ultra fast (0.0002s read/write), small & encrypted mobile key-value storage framework for React Native written in C++ using JSI
https://rnmmkv.now.sh
MIT License
1.56k stars 109 forks source link

[Bug] Old settings are read after app reinstall #325

Closed glenne closed 1 year ago

glenne commented 1 year ago

Describe the bug After uninstalling the app and reinstalling, it reads stale settings data.

To Reproduce Steps to reproduce the behavior:

  1. Uninstall App, then Install the App
  2. Note that previous settings are read from MMKV. e.g. X=ABC
  3. Change setting X to XYZ
  4. Exit the app or even reboot the device. Do not uninstall.
  5. Start the App and note setting is X is still XYZ (good)
  6. Uninstall the App, then Install the App
  7. Note that settings restored have X=ABC (bad)

Where is this old setting coming from? Rebooting the device read back X=XYZ (good) but reinstalling reads back ABC (bad).

Expected behavior After app reinstall, the setting for X should be the last set value (XYZ), not some prior value (ABC)

Screenshots N/A

Platform Information:

Additional context Am using MMKV.getMapAsync and MMKV.setMapAsync. Init done with new MMKVLoader().initialize()

I attempted to enable logging and got the following trace. The files seem to magically appear when the app is started. If the app is uninstalled, where are the files coming from with old state?

05-10 17:08:29.854 26499 26914 I MMKV    : <MMKV.cpp:165::initialize> version v1.2.13, page size 4096, arch arm64-v8a
05-10 17:08:29.854 26499 26914 I MMKV    : <MMKV.cpp:176::initialize> armv8 AES instructions is supported
05-10 17:08:29.854 26499 26914 I MMKV    : <MMKV.cpp:184::initialize> armv8 CRC32 instructions is supported
05-10 17:08:29.854 26499 26914 I MMKV    : <MMKV.cpp:207::initializeMMKV> root dir: /data/user/0/net.entazza.crewtimer/files/mmkv
05-10 17:08:29.854 26499 26914 I MMKV    : <MemoryFile.cpp:97::open> open fd[0x6f], /data/user/0/net.entazza.crewtimer/files/mmkv/mmkvIDStore
05-10 17:08:29.854 26499 26914 I MMKV    : <MemoryFile.cpp:97::open> open fd[0x73], /data/user/0/net.entazza.crewtimer/files/mmkv/mmkvIDStore.crc
05-10 17:08:29.854 26499 26914 I MMKV    : <MMKV_IO.cpp:81::loadFromFile> loading [mmkvIDStore] with 83 actual size, file size 4096, InterProcess 0, meta info version:3
05-10 17:08:29.854 26499 26914 I MMKV    : <MMKV_IO.cpp:86::loadFromFile> loading [mmkvIDStore] with crc 1774334605 sequence 1 version 3
05-10 17:08:29.854 26499 26914 I MMKV    : <MMKV_IO.cpp:130::loadFromFile> loaded [mmkvIDStore] with 2 key-values
05-10 17:08:29.856 26499 26914 I MMKV    : <MMKV.cpp:207::initializeMMKV> root dir: /data/user/0/net.entazza.crewtimer/files/mmkv
05-10 17:08:29.859 26499 26914 I MMKV    : <MemoryFile.cpp:97::open> open fd[0x74], /data/user/0/net.entazza.crewtimer/files/mmkv/default
05-10 17:08:29.859 26499 26914 I MMKV    : <MemoryFile.cpp:97::open> open fd[0x80], /data/user/0/net.entazza.crewtimer/files/mmkv/default.crc
05-10 17:08:29.859 26499 26914 I MMKV    : <MMKV_IO.cpp:81::loadFromFile> loading [default] with 52147 actual size, file size 131072, InterProcess 0, meta info version:3
05-10 17:08:29.859 26499 26914 I MMKV    : <MMKV_IO.cpp:86::loadFromFile> loading [default] with crc 3152578544 sequence 11 version 3
05-10 17:08:29.859 26499 26914 I MMKV    : <MMKV_IO.cpp:130::loadFromFile> loaded [default] with 8 key-values
glenne commented 1 year ago

Argh! Problem solved.

Somehow on this device Samsung Backup and Restore was enabled and it had cached an old state. When the app was reinstalled the old state was brought in with the app and react-native-mmkv-storage did it's job and read it in as it should. Disabling Samsung Backup and Restore returned all to expected behavior. If only these manufacturer apps could be easily uninstalled...