Skip to content

Commit

Permalink
workaround for #3382
Browse files Browse the repository at this point in the history
On esp32, its possible that two threads (async_tcp, looptask) are sending out JSON via AsyncWebServer in parallel 
- serveJson() responds to json/si, and 
- updateInterfaces() is sending JSON state info using sendDataWs(). 

This workaround uses the INTERFACE_UPDATE_COOLDOWN timer  to delay the second webSocket send command so it does not (usually) interfere with the first.

It looks like the root cause that parts of AsyncWebServer are not thread-safe, and the payloads from a second ->send() call may corrupt the previous one if still being sent out.  The problem should be solved properly in AsyncWebServer, however until that happens, this workaround help to reduce the frequency of errors.
  • Loading branch information
softhack007 authored Oct 5, 2023
1 parent 26e766e commit e2886e8
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions wled00/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,8 @@ void serveJson(AsyncWebServerRequest* request)
JsonArray effects = lDoc.createNestedArray(F("effects"));
serializeModeNames(effects); // remove WLED-SR extensions from effect names
lDoc[F("palettes")] = serialized((const __FlashStringHelper*)JSON_palette_names);
} else {
lastInterfaceUpdate = millis(); // softhack007 #3382 - delay re-sending of same JSON in updateInterfaces()
}
//lDoc["m"] = lDoc.memoryUsage(); // JSON buffer usage, for remote debugging
}
Expand Down

0 comments on commit e2886e8

Please sign in to comment.