-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Corrupted data in response, when changing a preset #3641
Comments
Actually I experienced the #3447 issue in 0.14, but I don't see it in 0.15 |
The issue appeared when we updated ESP8266 platform in PIO. We cannot revert because newer NeoPixelBus requires it. |
I'm not 100% finished debugging yet, but I'm out of time for the moment, so I'll give a quick report. It's looking to me like the issue is re-use of the global ArduinoJSON buffer before the |
@willmmiles thanks to your hints I can now reliably reproduce corruption (not exactly the same as above, but it is consistent). It is indeed linked to use-after-free situation regarding JSON buffer. But not JSON document itself but strings within it. I wonder why that doesn't happen on ESP32 (and variants) but only on ESP8266. And not always at that. |
You're safe if the reply is less than the outbound TCP buffer size, so the server code could queue the entire response to the underlying IP stack before returning to the wled code. On ESP8266 that's 1024 bytes, which I think will cover most use cases of 2 segments or less. A quick google search suggests the ESP32 defaults to 5760 bytes, which will cover a lot more segments and effects without issues. And even then, it'll only have problems if something else tries to use the JSON buffer and overwrites the strings before the wifi code finishes the transfer (ie. a classic race condition). This didn't consistenly happen in my test setup -- depending on what else was going on, most of the time it would still complete successfully for me. |
Extend the JSON response class to hold the global JSON buffer lock until the transaction is completed. Fixes Aircoookie#3641
Closing as corrupt JSON has been fixed in 0.14.1-b3. |
What happened?
When requesting a preset change via JSON, I see some corrupted data in the response.
Preset changes successfully, but the response generates an error in Home Assistant, e.g.:
It happens most of the times.
Very rarely response is correct.
It happens when trying to activate any configured preset.
To Reproduce Bug
Example:
Expected Behavior
Install Method
Self-Compiled
What version of WLED?
0.15, 202401010
Which microcontroller/board are you seeing the problem on?
ESP8266
Relevant log/trace output
No response
Anything else?
Issue probably exists also on 0.14.0, see: home-assistant/core#106375
Code of Conduct
The text was updated successfully, but these errors were encountered: