Skip to content

Commit

Permalink
Defer web requests if JSON lock contended
Browse files Browse the repository at this point in the history
Use the web server's queuing mechanism to call us back later.
  • Loading branch information
willmmiles committed Aug 5, 2024
1 parent 2ec36cd commit cc065f1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion wled00/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ void serveJson(AsyncWebServerRequest* request)
}

if (!requestJSONBufferLock(17)) {
serveJsonError(request, 503, ERR_NOBUF);
request->deferResponse();
return;
}
// releaseJSONBufferLock() will be called when "response" is destroyed (from AsyncWebServer)
Expand Down
5 changes: 4 additions & 1 deletion wled00/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,10 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
//USERMODS
if (subPage == SUBPAGE_UM)
{
if (!requestJSONBufferLock(5)) return;
if (!requestJSONBufferLock(5)) {
request->deferResponse();
return;
}

// global I2C & SPI pins
int8_t hw_sda_pin = !request->arg(F("SDA")).length() ? -1 : (int)request->arg(F("SDA")).toInt();
Expand Down
2 changes: 1 addition & 1 deletion wled00/wled_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ void initServer()
bool isConfig = false;

if (!requestJSONBufferLock(14)) {
serveJsonError(request, 503, ERR_NOBUF);
request->deferResponse();
return;
}

Expand Down

0 comments on commit cc065f1

Please sign in to comment.