Open Luca96 opened 8 months ago
Hello @Luca96
It seems like the issue is because the stack size is small for the async handler task:
#define ASYNC_WORKER_TASK_STACK_SIZE 2048
Can you try increasing the stack size and test it again. Please let me know if it helps.
Thanks!
Hi @hmalpani , thanks for the help but increasing the task stack size still not works: I increased it to 16k but now I get a different error:
I (111177) file_server: invoking /upload/file.png
I (111187) file_server: Receiving file : /file.png...
I (111187) file_server: Remaining size : 16221
I (111207) file_server: Remaining size : 11517
I (111227) file_server: Remaining size : 6973
I (111237) file_server: Remaining size : 4480
W (116227) httpd_txrx: httpd_sock_err: error in recv : 11
W (116227) httpd_txrx: httpd_sock_err: error in recv : 128
E (116297) file_server: File reception failed! Error type: -1 (Socket is not connected)
W (116307) httpd_txrx: httpd_resp_send_err: error calling setsockopt : 9
W (116317) httpd_txrx: httpd_sock_err: error in send : 9
which is about the underlying socket being disconnected.
I've also noticed that the async task fails, then it gets resubmitted but fails again. Moreover, I tried to upload another file, getting the usual error:
assert failed: lwip_recv_tcp /IDF/components/lwip/lwip/src/api/sockets.c:1001 (invalid copylen)
Should I change the HTTP server config too? Like the core_id
, task_priority
and stack_size
? Thanks
@chipweinberger maybe you know . ..
not sure of a reason.
seems lwip related
Try enable LWIP_DEBUG to check the values of p->tot_len, recv_left, recvd and copylen before the assertion.
I was able to reproduce the reported problems and confirm that there's a race condition in LWIP.
Thanks @Luca96 for sharing all these details and steps to reproduce it. Apologies for not handling this sooner, looks like a pretty nasty bug in lwip (socket owned cached pbuf not protected):
It was failing on v5.2, but working on the latest IDF, yet probably just because of the way worker threads are run in the latest http server.
I'm not sure how to fix the issue correctly at the moment, but will come up with some workaround at least in the following days.
Answers checklist.
IDF version.
v5.2-beta1
Espressif SoC revision.
ESP32-D0WD-V3 (revision v3.1)
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
CMD
Development Kit.
ESP32-WROOM-32
Power Supply used.
USB
What is the expected behavior?
The expected behavior is to handle file upload requests by the server, asynchronously. The
httpd_req_recv
function should receive a chunk of bytes without failing, such that the received bytes can be then written on an SD card. The whole thing handled by FreeRTOS's tasks.What is the actual behavior?
When the task is invoked by the FreeRTOS sheduler, the file upload handler manages to receive a few chunks but then crashes suddenly, apparently at random points during the upload. The error I get is:
and is triggered by the
httpd_req_recv
function.Steps to reproduce.
Basically my code merges the async_handlers example with the file_serving one. The example code is:
The web server's index HTML page is (which is embedded by CMake):
Moreover, I use the ESP32 as a Wi-Fi AP from which I connect to it with my laptop and open the web server at the given IP address: in my case is
192.16.4.1
.The code for the Soft AP (
wifi_ap.h
) is:Debug Logs.
More Information.
From the
menuconfig
:CONFIG_EXAMPLE_MAX_ASYNC_REQUESTS=2
.My
CMakeLists.txt
is:I also say that the whole code works fine without the async part, i.e., without using the FreeRTOS's tasks.