-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nvs: nvs_set_*() calls on same key but different types succeed and create multiple entries (IDFGH-9727) #11062
Comments
@crackwitz Thanks for reporting the issue. Indeed, the docs are wrong — we never checked whether there is an existing key-value pair with the same key but a different type, during the write operation. It's possible to fix this so that it behaves as described in the docs, however we would have to be careful about this... Existing applications may have relied on this (incorrect) behavior, so worst case fixing this might affect devices deployed in the field after they are updated to use the new IDF version. We can update the docs to describe the existing behavior as the first step, then revisit this bug before the next major release (v6.0) |
Allow me to describe the behavior I see. Multiple entries for the same key can exist, even multiple entries for the same key and type. I shall refer to them in order of iteration, "top" (older) to "bottom" (newer).
There is no way to get the value of any entry but the topmost one. In some situations, the topmost entry will not even be erased by an update (set), which means that set() calls on an inconsistent state may not have a direct effect. Given the right sequence of set() calls, I can produce an arbitrary amount of entries with arbitrary types, all with the same key. I bow before anyone who relies on that behavior. ;) |
That's a very good point! Indeed this can lead to the behavior which is pretty confusing and hard to troubleshoot. |
Hi @crackwitz, We have had internal discussion and it resulted in making the nvs_set* behaviour more predictable while respecting the numerous implementations already deployed in the field. As Is state: We believe this compromise helps to reduce potential risks and reduces efforts required at users side when updating their applications. |
Answers checklist.
IDF version.
v5.0.1
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
PowerShell
Development Kit.
ESP32 Ethernet Kit
Power Supply used.
USB
What is the expected behavior?
nvs_set_*()
returns error code indicating that the key exists but has a different type.What is the actual behavior?
nvs_set_*()
call succeeds, creates additional entry for the same key.Steps to reproduce.
Note: presence/absence of commit() calls makes no difference.
Debug Logs.
No response
More Information.
The call creates multiple entries for the same string key, as visible from
nvs_entry_find()
.I can even create multiple entries with the same type.
The data of all
set()
calls does make it into the partition. I can access all of it by repeatedly deleting the topmost entry, which reveals the value of the next entry for that key.This directly contradicts documentation.
The text was updated successfully, but these errors were encountered: