Repository navigation
Single json buffer - #2336
Single json buffer#2336
Conversation
|
Config and ledmap are safe. I can see problems on serial, MQTT or network access. |
|
I have identified potential lockup in:
Oddly though, ESP8266 never locked up. |
|
Got it! ... and there was a lock-up. |
|
Recent commits are without locking up ESP. Looks promising. Edit: With multiple (>2) simultaneous requests to ESP8266 I can see occasional reboot. |
Dadded debugging information.
|
A lot less reboots on ESP8266 since latest push. 😀 |
|
Upadte: ESP8266 (and ESP32) running smooth for 2 days now. No issues whatsoever. |
(to be implemented in #2336 )
| { | ||
| unsigned long now = millis(); | ||
|
|
||
| while (jsonBufferLock && millis()-now < 1000) delay(1); // wait for a second for buffer lock |
There was a problem hiding this comment.
I thought to myself that this can't possibly work, because delay() in ESP8266 network callbacks will crash and burn.
Turns out that this does in fact work, because ESP8266 and 32 differ in behavior:
ESP8266 would be stuck for a second and not reply to the request in the best case and crash in the worst case if it encountered a locked buffer in a network callback. Luckily this should never happen as the ESP8266 can only handle network callbacks wherever yield() is placed. As such, as long as we make sure we never call yield() while the buffer is locked, we are 100% fine. In fact, buffer lock logic is not required at all on ESP8266 since there is simply no way for two interactions that both need the buffer to intersect.
On ESP32, the buffer lock is needed and works as intended! Due to being dual core, network callbacks are run on core 1 while the main loop is run on core 0. If core 1 handles a network request, it will wait out the lock, as (unlike with 8266) the loop task will continue to run, thus only blocking for a few milliseconds at most.
I'm interested in how ESP32-S2 would behave here, given that it is single core. I would assume same as ESP8266, but it might also be running two tasks on the same core (and rapidly switching between them).
In both cases, it should work fine.
I think this is ready for merge and public testing as part of 0.13.0-b6 :)
There was a problem hiding this comment.
Never thought about implications of net callbacks since I was unaware of the limitations.
Still, this code is now running bug free for a month on a ESP01, D1 mini and D1 min32.
I went so far as to install it on all of my production units. Not a single one of them has crashed since!
(to be implemented in wled#2336 )
* Single/static JSON buffer for all requests. * Missing json.cpp changes. * Async fix. * Added conditional compile (WLED_USE_DYNAMIC_JSON). * Advanced locking with time-out. * Missing releaseJSONBufferLock() on error response. * Fix for config saving. * Fixes and optimisations. Dadded debugging information. * Fix for ledmaps. * No unsolicited serial sending if GPIO1 allocated * Stray semicolons * Fix JSON ledmap Co-authored-by: Blaz Kristan <[email protected]>
JSON buffer is statically allocated, this should help reduce memory fragmentation and also offer a small performance benefit.
Need to check that this works if a network request comes in while something in the loop is using the buffer (IR/config/ledmap/preset cycle/serial/MQTT)
By @blazoncek