khoih-prog / AsyncWebServer_RP2040W

Asynchronous WebServer Library for RASPBERRY_PI_PICO_W using CYW43439 WiFi with arduino-pico core. This library, which is relied on AsyncTCP_RP2040W, is part of a series of advanced Async libraries for RP2040W, such as AsyncTCP_RP2040W, AsyncUDP_RP2040W, AsyncWebServer_RP2040W, AsyncHTTPRequest_RP2040W, AsyncHTTPSRequest_RP2040W, etc. Now can display programmed WiFi country-code and support using CString to save heap to send very large data
GNU Lesser General Public License v3.0
24 stars 6 forks source link

AsyncWebSocketServer_RP2040W crashes with "[AWS] ERROR: Too many messages queued" #6

Closed drmue closed 2 years ago

drmue commented 2 years ago

Dear Khoih,

Thank you for release 1.3.0. However, the AsyncWebSocket server crashes after a while. In my current project, a value is transferred to the browser every 20 ms and displayed there in a canvas. After a while the canvas freezes. After disconnecting and reconnecting the serial monitor, it says "[AWS] ERROR: Too many messages queued". I implemented a counter on the website to see after how many transmissions the crash occurs. The number of transfers seems to be random after the crash happens.

  1. Load PicoAsyncSocB onto the Pi pico W

  2. Connect to the socket server with a browser

  3. Wait a moment

As you might have guessed, I've also tried all of this with "ESPAsyncWebServer" on an EspNode board, and nothing crashes there.

Best regards drmue

PicoWAsyncSockB.zip

toomanymessages

crash1090

crash3108


Arduino IDE version: 1.8.19
RP2040 core v2.6.0
RASPBERRY_PI_PICO_W Module
OS: Ubuntu 20.04 LTS
Linux xy-Inspiron-3593 5.15.0-48-generic #54~20.04.1-Ubuntu SMP Thu Sep 1 16:17:26 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
revell1 commented 2 years ago

Probably not related, but may be of interest. I have been trying to get a stable web server to run on my Pico-W for some time, I have tried reverting to the example web server in the Arduino IDE examples for the Pico-W. Even with that, I get random deaths of the server response. Though that generally ends with not managing to get a reconnection to the Pico-W even though it still responds to Pings, and can Ping external targets. During my investigations, I have also seen variation in the response times for the Pico-W, so wonder if your random failure could be linked with this variability in responses, possibly causing a backlog of messages. This would point to a lower level of the Pico-W driver code as being a problem.

khoih-prog commented 2 years ago

Hi all,

There are something you have to take into consideration

  1. WebSockets (WS) has pros and cons,compared to regular TCP regular Sockets. WS must be used correctly, when absolutely necessary in certain use-cases. It's not designed for very high speed because of some trade-offs for two-way communication.

From RFC6455

The WebSocket Protocol enables two-way communication between a client running untrusted code in a controlled environment to a remote host that has opted-in to communications from that code. The security model used for this is the origin-based security model commonly used by web browsers. The protocol consists of an opening handshake followed by basic message framing, layered over TCP. The goal of this technology is to provide a mechanism for browser-based applications that need two-way communication with servers that does not rely on opening multiple HTTP connections (e.g., using XMLHttpRequest or