-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Handle preset deletion asynchronously for consistency with preset saving #4348
Comments
this looks like it could solve some issues users have with corrupted files (as referenced by @softhack007) |
Sure, I'll create a PR |
Asynchronous preset handling was introduced to combat preset corruption that was seen on certain ESP32 devices (I am unaware of "regular" corruption on ESP8266, ESP32-C3, ESP32-S2 or ESP32-S3). As discussed elsewhere the corruption most likely comes from old and inadequate bootloader/framework configuration used in those devices. If there was no such corruption occurring all preset handling would still be synchronous/immediate. Which would render your implementation of BLE useless. So this raises the question: where should this be fixed? In WLED core or in your solution? IMO when we update ESP32 binaries to use newer bootloader and recent framework preset handling should be executed synchronously (as asynchronous has its drawbacks that had to be mitigated) as it was in the past. |
@blazoncek Thanks for your input. My point here is more about consistency, that saving and deleting are approached in different ways as of now. Which option to choose of course depends on where WLED is heading in general with immediate vs. asynchronous operations. Let me know if a PR might be useful still. |
I would prefer synchronous preset handling as it has less drawbacks than current implementation. After we solve corruption issues, one way or the other. |
Probably we need a mutex over the presets database. I think the current code can get in to a lot of trouble if there's requests via different APIs in flight. |
I disagree. We need to fix preset corruption and then return original immediate/synchronous preset (load/save/delete) handling. |
File corruption can be caused by attempting parallel operations on the same file from different tasks (eg. web server callback is writing while loop is trying to read -- or worse, also trying to write). Maybe I haven't been around long enough, but if I was facing corruption issues, the first thing I'd try is making sure only one task can use the file at a time, so every operation runs to completion before the next operation can see the changes. |
Is your feature request related to a problem? Please describe.
I'm developing a BLE mod for wled which works fine for commands except preset/playlist deletion (device crashes). I then noticed that presets are deleted using immediate file operations rather than asynchronously using flags, which is how presets are saved for example. Same for API calls. Is this there a reason for this or a bug? Issue solved if I move deletion to be handled later in the main loop (see below).
Deletion still works fine using wifi, but thought it might be a general stability improvement anyway.
Describe the solution you'd like
In
presets.cpp
: Instead of directly initiating file operations indeletePreset(index)
, called fromdeserializeState
, set a flagpresetToDelete = index
that's picked up inhandlePresets()
. Something like this:Adds consistent behaviour between preset deletion and saving, and prevents potential blocking operations during preset deletion.
The text was updated successfully, but these errors were encountered: