From 80b906999b2e85aa9948591b15e8ae2875b21292 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Tue, 30 Dec 2025 01:57:46 +0100 Subject: [PATCH] requestJSONBufferLock() variable timeout * default timeout = 1800ms * reduced timeout for ws (300ms) --- wled00/fcn_declare.h | 2 +- wled00/util.cpp | 6 +++--- wled00/ws.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wled00/fcn_declare.h b/wled00/fcn_declare.h index 73b23566..5cfcff46 100644 --- a/wled00/fcn_declare.h +++ b/wled00/fcn_declare.h @@ -439,7 +439,7 @@ void sappend(char stype, const char* key, int val); void sappends(char stype, const char* key, char* val); void prepareHostname(char* hostname); bool isAsterisksOnly(const char* str, byte maxLen) __attribute__((pure)); -bool requestJSONBufferLock(uint8_t module=255); +bool requestJSONBufferLock(uint8_t module=255, unsigned timeoutMS = 1800); void releaseJSONBufferLock(); uint8_t extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen); uint8_t extractModeSlider(uint8_t mode, uint8_t slider, char *dest, uint8_t maxLen, uint8_t *var = nullptr); diff --git a/wled00/util.cpp b/wled00/util.cpp index 23e458e0..06e32dfa 100644 --- a/wled00/util.cpp +++ b/wled00/util.cpp @@ -220,19 +220,19 @@ bool isAsterisksOnly(const char* str, byte maxLen) //threading/network callback details: https://github.com/Aircoookie/WLED/pull/2336#discussion_r762276994 -bool requestJSONBufferLock(uint8_t module) +bool requestJSONBufferLock(uint8_t module, unsigned timeoutMS) { bool haveLock = false; #ifdef ARDUINO_ARCH_ESP32 // We use a recursive mutex to prevent parallel JSON writes from parallel tasks. // This also fixes hanging up for the full timeout interval in cases when the contention is from the same task. // see https://github.com/wled/WLED/pull/4089 for more details. - if (esp32SemTake(jsonBufferLockMutex, 1800) == pdTRUE) haveLock = true; // WLEDMM must wait longer than suspendStripService timeout = 1500ms + if (esp32SemTake(jsonBufferLockMutex, timeoutMS) == pdTRUE) haveLock = true; // WLEDMM must wait longer than suspendStripService timeout = 1500ms #else // 8266: only wait in case that can_yield() tells us we can yield and delay if (can_yield()) { unsigned long now = millis(); - while (jsonBufferLock && millis()-now < 1800) delay(1); // wait for fraction for buffer lock // WLEDMM must wait longer than suspendStripService timeout = 1500ms + while (jsonBufferLock && millis()-now < timeoutMS) delay(1); // wait for fraction for buffer lock // WLEDMM must wait longer than suspendStripService timeout = 1500ms if (!jsonBufferLock) haveLock = true; } #endif diff --git a/wled00/ws.cpp b/wled00/ws.cpp index 52efd664..246d09bc 100644 --- a/wled00/ws.cpp +++ b/wled00/ws.cpp @@ -49,7 +49,7 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp } bool verboseResponse = false; - if (!requestJSONBufferLock(11)) { + if (!requestJSONBufferLock(11, 300)) { client->text(F("{\"error\":3}")); // ERR_NOBUF return; } @@ -138,7 +138,7 @@ void sendDataWs(AsyncWebSocketClient * client) DEBUG_PRINTF("sendDataWs\n"); if (!ws.count()) return; - if (!requestJSONBufferLock(12)) { + if (!requestJSONBufferLock(12, 300)) { if (client) { client->text(F("{\"error\":3}")); // ERR_NOBUF } else {