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

ESP32 websocket crash at AsyncClient::space() #739

Closed
Civilduino opened this issue Apr 6, 2020 · 7 comments
Closed

ESP32 websocket crash at AsyncClient::space() #739

Civilduino opened this issue Apr 6, 2020 · 7 comments
Labels

Comments

@Civilduino
Copy link

Civilduino commented Apr 6, 2020

Hello,

My ESP32 keep crashing when using this library with websocket. The crash happens after I refresh Safari in my Iphone while my computer with Firefox is also connected to the server (i.e. two clients). Refreshing Firefox with my Iphone connected does NOT cause a crash (I tested several times). However if I refresh very fast my computer I get the crash.

Also tried Microsoft Edge in my phone with the same results.

Appreciate any help! :)

Hardware

MacBook Air, Mojave
Wemos LOLIN D32 Pro
CAN transceiver SN65HVD230

Software

Platformio.io Core 4.3.1, Home 3.1.1 using Visual Code IDE

CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/lolin_d32_pro.html
PLATFORM: Espressif 32 1.12.0 > WEMOS LOLIN D32 PRO
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:

  • framework-arduinoespressif32 3.10004.200129 (1.0.4)
  • tool-esptoolpy 1.20600.0 (2.6.0)
  • toolchain-xtensa32 2.50200.80 (5.2.0)
    LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 29 compatible libraries
    Scanning dependencies...
    Dependency Graph
    |-- ESP Async WebServer 1.2.3
    | |-- AsyncTCP 1.1.1
    | |-- WiFi 1.0
    | |-- FS 1.0
    | |-- ArduinoJson 6.15.0
    |-- WiFi 1.0
    |-- ArduinoJson 6.15.0
    |-- Ticker 1.1
    |-- ESPmDNS 1.0
    | |-- WiFi 1.0
    |-- SPIFFS 1.0
    | |-- FS 1.0
    Building in release mode
    Retrieving maximum program size .pio/build/lolin_d32_pro/firmware.elf
    Checking size .pio/build/lolin_d32_pro/firmware.elf
    Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
    RAM: [= ] 14.1% (used 46192 bytes from 327680 bytes)
    Flash: [======== ] 77.8% (used 1020005 bytes from 1310720 bytes)

CAN driver from ESP-IDF

Sketch

See attached file here.

Backtrace from Platformio

Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x40181657 PS : 0x00060930 A0 : 0x8016d24c A1 : 0x3ffd37d0
A2 : 0x00000000 A3 : 0x40084f08 A4 : 0x00000001 A5 : 0x00000000
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x8000beb2 A9 : 0x3ffd37b0
A10 : 0x3ffd4e64 A11 : 0x00000008 A12 : 0x3ffd38ec A13 : 0x3ffd38f0
A14 : 0x3ffd38f4 A15 : 0x3ffd38f8 SAR : 0x00000010 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000 LBEG : 0x4000c349 LEND : 0x4000c36b LCOUNT : 0xffffffff

Backtrace: 0x40181657:0x3ffd37d0 0x4016d249:0x3ffd37f0 0x400d41fc:0x3ffd3810 0x400d4227:0x3ffd3830 0x400d423d:0x3ffd3850 0x400d424d:0x3ffd3870 0x400d17a4:0x3ffd3890 0x4017dcdf:0x3ffd38b0 0x4017df9e:0x3ffd38d0 0x400d475d:0x3ffd3920 0x400d477d:0x3ffd3940 0x400d48d5:0x3ffd3960 0x400d4922:0x3ffd39a0 0x400d492f:0x3ffd39c0 0x4016d512:0x3ffd39e0 0x4016d646:0x3ffd3a10 0x4016d65c:0x3ffd3a30 0x4016d91e:0x3ffd3a50 0x40088b7d:0x3ffd3a80

Decoding of backtrace

#0 0x40181657:0x3ffd37d0 in AsyncClient::space() at /AsyncTCP_ID1826/src/AsyncTCP.cpp:1020
#1 0x4016d249:0x3ffd37f0 in AsyncClient::canSend() at /AsyncTCP_ID1826/src/AsyncTCP.cpp:1020
#2 0x400d41fc:0x3ffd3810 in AsyncWebSocketClient::_queueMessage(AsyncWebSocketMessage*) at /ESP Async WebServer_ID306/src/AsyncWebSocket.cpp:850
#3 0x400d4227:0x3ffd3830 in AsyncWebSocketClient::text(char const*, unsigned int) at /ESP Async WebServer_ID306/src/AsyncWebSocket.cpp:850
#4 0x400d423d:0x3ffd3850 in AsyncWebSocketClient::text(char*) at /ESP Async WebServer_ID306/src/AsyncWebSocket.cpp:850
#5 0x400d424d:0x3ffd3870 in AsyncWebSocketClient::text(char const*) at ??:?
#6 0x400d17a4:0x3ffd3890 in onEvent(AsyncWebSocket*, AsyncWebSocketClient*, AwsEventType, void*, unsigned char*, unsigned int) at src/inclino_server.cpp:25
#7 0x4017dcdf:0x3ffd38b0 in std::_Function_handler<void (AsyncWebSocket*, AsyncWebSocketClient*, AwsEventType, void*, unsigned char*, unsigned int), void ()(AsyncWebSocket, AsyncWebSocketClient*, AwsEventType, void*, unsigned char*, unsigned int)>::_M_invoke(std::_Any_data const&, AsyncWebSocket*&&, AsyncWebSocketClient*&&, AwsEventType&&, void*&&, unsigned char*&&, unsigned int&&) at /Users/pan/.platformio/packages/toolchain-xtensa32@2.50200.80/xtensa-esp32-elf/include/c++/5.2.0/functional:1871
#8 0x4017df9e:0x3ffd38d0 in std::function<void (AsyncWebSocket*, AsyncWebSocketClient*, AwsEventType, void*, unsigned char*, unsigned int)>::operator()(AsyncWebSocket*, AsyncWebSocketClient*, AwsEventType, void*, unsigned char*, unsigned int) const at /Users/pan/.platformio/packages/toolchain-xtensa32@2.50200.80/xtensa-esp32-elf/include/c++/5.2.0/functional:2271
(inlined by) AsyncWebSocket::_handleEvent(AsyncWebSocketClient*, AwsEventType, void*, unsigned char*, unsigned int) at /ESP Async WebServer_ID306/src/AsyncWebSocket.cpp:872
#9 0x400d475d:0x3ffd3920 in AsyncWebSocketClient::~AsyncWebSocketClient() at /ESP Async WebServer_ID306/src/AsyncWebSocket.cpp:850
#10 0x400d477d:0x3ffd3940 in std::_Function_handler<void (AsyncWebSocketClient* const&), AsyncWebSocket::AsyncWebSocket(String const&)::{lambda(AsyncWebSocketClient*)#1}>::_M_invoke(std::_Any_data const&, AsyncWebSocketClient* const&) at /ESP Async WebServer_ID306/src/AsyncWebSocket.cpp:850
(inlined by) _M_invoke at /Users/pan/.platformio/packages/toolchain-xtensa32@2.50200.80/xtensa-esp32-elf/include/c++/5.2.0/functional:1871
#11 0x400d48d5:0x3ffd3960 in std::function<void (AsyncWebSocketClient* const&)>::operator()(AsyncWebSocketClient* const&) const at /ESP Async WebServer_ID306/src/AsyncWebSocket.cpp:850
(inlined by) LinkedList<AsyncWebSocketClient*, LinkedListNode>::remove_first(std::function<bool (AsyncWebSocketClient* const&)>) at /ESP Async WebServer_ID306/src/StringArray.h:150
(inlined by) AsyncWebSocket::_handleDisconnect(AsyncWebSocketClient*) at /ESP Async WebServer_ID306/src/AsyncWebSocket.cpp:884
#12 0x400d4922:0x3ffd39a0 in AsyncWebSocketClient::_onDisconnect() at /ESP Async WebServer_ID306/src/AsyncWebSocket.cpp:850
#13 0x400d492f:0x3ffd39c0 in std::_Function_handler<void (void*, AsyncClient*), AsyncWebSocketClient::AsyncWebSocketClient(AsyncWebServerRequest*, AsyncWebSocket*)::{lambda(void*, AsyncClient*)#5}>::_M_invoke(std::_Any_data const&, void*&&, AsyncClient*&&) at /ESP Async WebServer_ID306/src/AsyncWebSocket.cpp:850
(inlined by) _M_invoke at /Users/pan/.platformio/packages/toolchain-xtensa32@2.50200.80/xtensa-esp32-elf/include/c++/5.2.0/functional:1871
#14 0x4016d512:0x3ffd39e0 in std::function<void (void*, AsyncClient*)>::operator()(void*, AsyncClient*) const at /AsyncTCP_ID1826/src/AsyncTCP.cpp:1020
#15 0x4016d646:0x3ffd3a10 in AsyncClient::_fin(tcp_pcb*, signed char) at /AsyncTCP_ID1826/src/AsyncTCP.cpp:1020
#16 0x4016d65c:0x3ffd3a30 in AsyncClient::_s_fin(void*, tcp_pcb*, signed char) at /AsyncTCP_ID1826/src/AsyncTCP.cpp:1020
#17 0x4016d91e:0x3ffd3a50 in _async_service_task(void*) at /AsyncTCP_ID1826/src/AsyncTCP.cpp:1020
(inlined by) _async_service_task at /AsyncTCP_ID1826/src/AsyncTCP.cpp:194
#18 0x40088b7d:0x3ffd3a80 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)

@Civilduino
Copy link
Author

Civilduino commented Apr 9, 2020

I figured out where in the code is the problem but not sure why. It is when calling the WebSocket onEvent function which looks like:

void onEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) { //Handle WebSocket event client->text("Hello from server!"); }

that is initialised before the server.begin() as
ws.onEvent(onEvent); server.addHandler(&ws);

If I comment out the onEvent function everything works as it should. What I am missing?

@BlueAndi
Copy link

BlueAndi commented Apr 9, 2020

Your sketch shows not the whole sourcecode. Push all, inclusive your onEvent handler.

@Civilduino
Copy link
Author

I updated the repository here

@BlueAndi
Copy link

If you remove your client cleanup functionality, does it still crash?

@Civilduino
Copy link
Author

Civilduino commented Apr 18, 2020

Yes it still does. It seems that the problem is that it trys to send two messages at the same time? one from ws.textAll() and other from client->text()

Try it yourself, it is a very simple example

@stale
Copy link

stale bot commented Jun 17, 2020

[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 Jun 17, 2020
@stale
Copy link

stale bot commented Jul 1, 2020

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Jul 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants