Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

ERROR: Too many messages queued even if AsyncWebSocket::availableForWriteAll() returns true #1158

Open
alex-fu27 opened this issue May 15, 2022 · 15 comments

Comments

@alex-fu27
Copy link

I have a lot of data I need to send out via an AsyncWebSocket in multiple messages in a loop. So I thought I could wait for AsyncWebSocket::availableForWriteAll() to return true, then write my data:

AsyncWebSocket ws;
// ....
void dump() {
    for (int i /* etc ... */) {
        while (!ws.availableForWriteAll()) {
             vTaskDelay(1);
             /* or delay(100) tried both */
        }
        ws.textAll(/* some data */);
    }
}

And while I expected this to wait until all queues have enough space, I am getting "ERROR: Too many messages queued" and even a watchdog timeout:

E (20378) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (20378) task_wdt:  - async_tcp (CPU 0/1)
E (20378) task_wdt: Tasks currently running:
E (20378) task_wdt: CPU 0: IDLE0
E (20378) task_wdt: CPU 1: IDLE1
E (20378) task_wdt: Aborting.
abort() was called at PC 0x40147e6c on core 0

ELF file SHA256: 0000000000000000

Backtrace: 0x400885d8:0x3ffbfa40 0x40088855:0x3ffbfa60 0x40147e6c:0x3ffbfa80 0x40086efd:0x3ffbfaa0 0x40179347:0x3ffbcbb0 0x40149777:0x3ffbcbd0 0x4008b015:0x3ffbcbf0 0x40089866:0x3ffbcc10
  #0  0x400885d8:0x3ffbfa40 in invoke_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:715
  #1  0x40088855:0x3ffbfa60 in abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:715
  #2  0x40147e6c:0x3ffbfa80 in task_wdt_isr at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/task_wdt.c:252
  #3  0x40086efd:0x3ffbfaa0 in _xt_lowint1 at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/xtensa_vectors.S:1154
  #4  0x40179347:0x3ffbcbb0 in esp_pm_impl_waiti at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/pm_esp32.c:492
  #5  0x40149777:0x3ffbcbd0 in esp_vApplicationIdleHook at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/freertos_hooks.c:108
  #6  0x4008b015:0x3ffbcbf0 in prvIdleTask at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/tasks.c:3507
  #7  0x40089866:0x3ffbcc10 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)

I am on an ESP32, platformio, ESP Async WebServer 1.2.3, AsyncTCP 1.1.1

@stale
Copy link

stale bot commented Jul 31, 2022

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 31, 2022
@Elbi2512
Copy link

I'v the same issue. The Flag of the availableForWriteAll is raised, but never cleared, at least not before the EPS reboots, with a remark that's it dit not received enought love in the Async handling routine. Looks like an interal issue/bug.

@stale
Copy link

stale bot commented Aug 16, 2022

[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.

@stale stale bot removed the stale label Aug 16, 2022
@stale
Copy link

stale bot commented Nov 2, 2022

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 2, 2022
@DeeEmm
Copy link

DeeEmm commented Dec 1, 2022

Same issue here

@stale
Copy link

stale bot commented Dec 1, 2022

[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.

@stale stale bot removed the stale label Dec 1, 2022
@AcuarioCat
Copy link

Somewhat related..
The queue size in AsyncTCP is very small, 32 messages. Unless you are very tight on memory this can be increased substantially (I set mine to 256) as it does not use much memory.
If you increase the size you can also increase the defines in AsyncEventSource.h SSE_MAX_QUEUED_MESSAGES
and AsyncWebSocket.h WS_MAX_QUEUED_MESSAGES.
This will allow many more messages on the AsyncTCP queue and should prevent (or reduce..) any ERROR messages.

@DeeEmm
Copy link

DeeEmm commented Jan 21, 2023

@AcuarioCat great info. Thanks.

How do you increase the memory allocation for queue size?

@AcuarioCat
Copy link

The queue size is set in AsyncTCP.cpp, you need to change xQueueCreate from 32 to the size you want.

@brunolalb
Copy link

brunolalb commented Feb 24, 2023

I have the same issue.
I'm on Arduino IDE 2.0.3, ESP32 2.0.7, latest code from ESP Async WebServer Github, latest code from AsyncTCP Github

My application basically sends a lot of JSON data (around 30kB/sec divided in 15 packages/sec). It works for a few seconds, heap stays stable and eventually the heap fills and the ESP reboots. This is the backtrace:

0x400de2b7: _tcp_poll at /home/bruno/Arduino/libraries/AsyncTCP-master/src/AsyncTCP.cpp:259
0x4010ac7d: tcp_slowtmr at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/core/tcp.c:1425
0x4010ad27: tcp_tmr at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/core/tcp.c:242
0x4010e19f: tcpip_tcp_timer at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/core/timeouts.c:161
0x4010e25d: sys_check_timeouts at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/core/timeouts.c:411
0x40106379: tcpip_timeouts_mbox_fetch at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/api/tcpip.c:104
0x40106379: tcpip_thread at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/api/tcpip.c:148

@06GitHub
Copy link

06GitHub commented May 6, 2023

[[AcuarioCat] The queue size is set in AsyncTCP.cpp, you need to change xQueueCreate from 32 to the size you want.

Using ESPAsyncWebServer streaming https://gist.github.com/me-no-dev/d34fba51a8f059ac559bf62002e61aa3

Indeed changing queue size from 32 to 256 in AsyncTCP.cpp, solves "async_tcp watchdog error" for me :

Error

The following tasks > did not reset the watchdog in time: E (705728) task_wdt: - async_tcp > (CPU 0/1)

AsyncTCP.cpp OK

static inline bool _init_async_event_queue(){
    if(!_async_queue){
        //_async_queue = xQueueCreate(32, sizeof(lwip_event_packet_t *));
        _async_queue = xQueueCreate(256, sizeof(lwip_event_packet_t *));  // prevents "async_tcp" Watchdog error 
        if(!_async_queue){
            return false;
        }
    }
    return true;
}

Configuration
ESP32-S3 8Mb PSRAM 16Mb Flash
Arduino IDE 1.8.19 arduino-esp32 core 2.0.8
Wifi mode : Access Point

On Windows, AsyncTCP.cpp is located in C:\Users\USER\Documents\Arduino\libraries\AsyncTCP-master\src\AsyncTCP.cpp

@Rysiek6
Copy link

Rysiek6 commented May 22, 2023

When the AP disconnects, the AP's ESP32 continues to send Socket messages to the queue (this causes overflow).
The following Socket sending conditions eliminate this inconvenience.
(I can connect to the AP and disconnect, and the AP system does not throw any error messages)

if (WiFi.status() != WL_CONNECTED && WiFi.softAPgetStationNum() < 1) {
	// do not send --> ERROR: Too many messages queued
}else {
	notifyClients( String(a_kom) );  // send a message 
}
//----------

@l-pastor
Copy link

I have the same problem,

IDE Arduino 2.1.0
ESP32 WROOM 32D 4MB

@umartechboy
Copy link

Same here.
Sending a message every 100ms creates this error, sending it aafter 150ms solves it.

But after observing the behavior on my console, my hunch is that chucking for WL status should solve it. If(WiFi.status() != WL_CONNECTED).

@mide1337
Copy link

mide1337 commented Jan 13, 2024

The Problem is that I send a message every millisecond (or nanoseconds, depends on the esp32 cycle time). I made a timer error in my loop. Editing this line:

_async_queue = xQueueCreate(32, sizeof(lwip_event_packet_t *));

cannot change the fact that I have sent to much messages lmao.

But the OP has a different problem, I did not use the function he uses.

Laaouatni added a commit to Laaouatni/arduino-2024-2025-prove that referenced this issue Dec 22, 2024
…(comment) and me-no-dev/ESPAsyncWebServer#1158 that suggest to increase the number xQueueCreate available in the AsyncTCP.cpp library
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants