Closed Barabas5532 closed 2 years ago
Hello @Barabas5532 Thanks for reporting the issue. We are trying to solve this issue. Until then can you please provide some information on why you are calling this function in quick succession?
My project is a DSP audio processor for guitar. There are DSP algorithms running in the ESP32, and each of these has a number of parameters. The frontend is connected to the ESP32 using websockets. The frontend initialises itself by requesting the value of all the audio parameters. In response, the ESP32 sends a websocket frame for each parameter. This causes many websocket messages to be queued into the httpd work queue at the same time.
I have found a workaround by limiting the amount of queued work to a single item (https://github.com/ShrapnelDSP/ShrapnelMonorepo/commit/7139c99115cad40148c5c22d1a5aef08ffac776b), I would like to be able to remove this.
The project is open source, the relevant parts are:
httpd
taskHello @Barabas5532,
Please try the attached patch and let me know if it fixes your issue. I have created a new API httpd_queue_work_sync()
. Try using it instead of httpd_queue_work()
0001-esp_http_server-Add-httpd_queue_work_sync-API-for-sy.zip
This issue can also be solved by increasing the size of the UDP mailbox in menuconfig>component_config>LWIP>UDP.
Thanks, Harshit
Hi, I were also hit by this issue, but I cannot serialize the queue with semaphores as I need it asynchronous. I have found the root problem. It is shortage of MEMP_NETBUF buffers in LWIP. It fails in LWIP on this line: https://github.com/espressif/esp-lwip/blob/a45be9e438f6cf9c54ec150581819c3b95d5af6b/src/api/api_msg.c#L183
This can be solved by rising MEMP_NUM_NETBUF to some higher value (each buffer is about 36 bytes of size).
It also seems that lowering LWIP_LOOPBACK_MAX_PBUFS will at least notify the sender, that the work will never be done.
It is my understanding, that a proper fix would be to stop using socket as messaging layer and use some thread safe queue directly as all but one mallocs happen in the middle layers and are fundamentally not needed.
Environment
git describe --tags
to find it): v5.0-dev-1599-gb66cc63c41, v4.3.1xtensa-esp32-elf-gcc --version
to find it): xtensa-esp32-elf-gcc (crosstool-NG esp-2021r2) 8.4.0Problem Description
When
httpd_queue_work
is called in a tight loop, some of the work never gets executed. There are no warnings printed, the work function just never runs.Expected Behavior
Every call to
httpd_queue_work
causes a call to the work function.Actual Behavior
Sometimes the work function doesn't run after a call to
httpd_queue_work
.Steps to reproduce
I've added an assert that should fail when working as expected. This does fail if a 100 ms delay is introduced into the loop that calls
httpd_queue_work
.Code to reproduce this issue
https://github.com/ShrapnelDSP/ShrapnelMonorepo/tree/httpd-work-queue-leak-bug/bug-demo
Debug Logs
Other items if possible
build
folder: binary.zip