Description
I upgraded ESPAsyncWebServer from v3.1.0 to the latest v3.3.x and found out that beginChunkedResponse behaved differently. I am unsure what causes the exact issue, but the result is that my request acts like there is no file in the directory I am traversing.
I managed to git-bisect by hand and find the problematic commit: 571eac4
Before that commit, I can traverse File root for files inside. After that commit, I never enter the while loop.
Here is a simplified view of the function:
fs::FS &fileSystem = SD_MMC;
void handleList(AsyncWebServerRequest *request) {
File root = fileSystem.open("/");
String txt;
bool finished;
AsyncWebServerResponse *response = request->beginChunkedResponse(
"application/json",
[root, txt, finished]
(uint8_t* buffer, const size_t max_len, const size_t index) mutable
-> size_t
{
log_i("index %u, %u", index, max_len);
if (index == 0) { // <========================= Reached first (index 0)
txt = "[";
finished = false;
}
while (File file = root.openNextFile()) { // <==== never enters here
log_i("file %s", file.name());
txt += "\"" + file.name() + "\"",;
if (txt.length() > max_len) {
memcpy(buffer, txt.c_str(), max_len);
txt = txt.substring(max_len);
log_i("return %u", max_len);
return max_len;
}
}
if (!finished) {
finished = true;
txt += "]";
memcpy(buffer, txt.c_str(), txt.length());
root.close();
log_i("return %u", txt.length());
return txt.length();
} else { // <============================== Reached second (index 2)
log_i("return %u", 0);
return 0;
}
});
request->send(response);
}
Result:
Result in logs:
[ 34877][I][sdwifi.ino:682] operator()(): index 0, 5511
[ 34884][I][sdwifi.ino:728] operator()(): return 2
[ 35051][I][sdwifi.ino:682] operator()(): index 2, 5501
[ 35056][I][sdwifi.ino:731] operator()(): return 0
While when using commit 741841a it works and here is the output in logs:
[ 37648][I][sdwifi.ino:674] operator()(): index 0, 5511
[ 38298][I][sdwifi.ino:682] operator()(): file Lamp_Shade_1_PLA_1h17m.gcode
[ 38324][I][sdwifi.ino:720] operator()(): return 32
[ 38338][I][sdwifi.ino:674] operator()(): index 32, 5471
[ 38344][I][sdwifi.ino:723] operator()(): return 0
Full source code: Link to the source code where the issue happens
Board: esp32-pico-d4 (SD WIFI PRO)
Considering this is a dual-core ESP32, I did try to set CONFIG_ASYNC_TCP_RUNNING_CORE to 0 or 1 with no success.
Description
I upgraded ESPAsyncWebServer from v3.1.0 to the latest v3.3.x and found out that
beginChunkedResponsebehaved differently. I am unsure what causes the exact issue, but the result is that my request acts like there is no file in the directory I am traversing.I managed to git-bisect by hand and find the problematic commit: 571eac4
Before that commit, I can traverse
File rootfor files inside. After that commit, I never enter the while loop.Here is a simplified view of the function:
Result:
Result in logs:
While when using commit 741841a it works and here is the output in logs:
Full source code: Link to the source code where the issue happens
Board: esp32-pico-d4 (SD WIFI PRO)
Considering this is a dual-core ESP32, I did try to set
CONFIG_ASYNC_TCP_RUNNING_COREto0or1with no success.