Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash with error message: "Required to lock TCPIP core functionality" #10526

Closed
1 task done
mathieucarbou opened this issue Oct 25, 2024 · 27 comments · Fixed by #10529
Closed
1 task done

Crash with error message: "Required to lock TCPIP core functionality" #10526

mathieucarbou opened this issue Oct 25, 2024 · 27 comments · Fixed by #10529
Labels
Status: Awaiting triage Issue is waiting for triage

Comments

@mathieucarbou
Copy link
Contributor

mathieucarbou commented Oct 25, 2024

Description

I have several apps that I keep updated to lats Arduino RC.

3.1.0-RC1 work fine.

[env]
build_type = release
framework = arduino
platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.10-rc1/platform-espressif32.zip

Since RC2 (3.1.0-RC2), I am observing several crashes with always the same error, in STA mode (not in AP mode).

[env]
build_type = release
framework = arduino
platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.10-rc2/platform-espressif32.zip
[  3555][D][ESPCONNECT][1][arduino_events] [NETWORK_CONNECTING] WiFiEvent: ARDUINO_EVENT_WIFI_STA_GOT_IP
[  3558][D][ESPCONNECT][1][arduino_events] State: NETWORK_CONNECTING => NETWORK_CONNECTED
[  3568][D][JSY-UDP][1][arduino_events] NetworkState: NETWORK_CONNECTING => NETWORK_CONNECTED
[  3579][I][JSY-UDP][1][arduino_events] Connected with IP address 192.168.125.130
[  3579][I][JSY-UDP][1][core] Enable Network Services...
[  3589][I][JSY-UDP][1][core] Enable Web Server...

assert failed: tcp_alloc /IDF/components/lwip/lwip/src/core/tcp.c:1851 (Required to lock TCPIP core functionality!)


Backtrace: 0x400832e5:0x3ffb23e0 0x4008c429:0x3ffb2400 0x400926d6:0x3ffb2420 0x400fb4cb:0x3ffb2550 0x400fb645:0x3ffb2570 0x40173517:0x3ffb2590 0x400dd44d:0x3ffb25e0 0x400d41b3:0x3ffb2600 0x400d4245:0x3ffb2640 0x400e01b5:0x3ffb2660 0x400e0440:0x3ffb2690 0x400e0481:0x3ffb26c0 0x400e04a5:0x3ffb26e0 0x4008cefe:0x3ffb2700
  #0  0x400832e5 in panic_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/panic.c:463
  #1  0x4008c429 in esp_system_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/port/esp_system_chip.c:92
  #2  0x400926d6 in __assert_func at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/assert.c:80
  #3  0x400fb4cb in tcp_alloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/tcp.c:1851 (discriminator 1)
  #4  0x400fb645 in tcp_new_ip_type at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/tcp.c:2006
  #5  0x40173517 in AsyncServer::begin() at .pio/libdeps/dev/AsyncTCP/src/AsyncTCP.cpp:1464 (discriminator 10)
  #6  0x400dd44d in AsyncWebServer::begin() at .pio/libdeps/dev/ESPAsyncWebServer/src/WebServer.cpp:120
  #7  0x400d41b3 in networkUpTask::{lambda(void*)#1}::operator()(void*) const at Sender.ino:240
  #8  0x400d4245 in void std::__invoke_impl<void, networkUpTask::{lambda(void*)#1}&, void*>(std::__invoke_other, networkUpTask::{lambda(void*)#1}&, void*&&) at /Users/mat/.platformio/packages/toolchain-xtensa-esp-elf/xtensa-esp-elf/include/c++/13.2.0/bits/invoke.h:61
      (inlined by) std::enable_if<is_invocable_r_v<void, networkUpTask::{lambda(void*)#1}&, void*>, void>::type std::__invoke_r<void, networkUpTask::{lambda(void*)#1}&, void*>(networkUpTask::{lambda(void*)#1}&, void*&&) at /Users/mat/.platformio/packages/toolchain-xtensa-esp-elf/xtensa-esp-elf/include/c++/13.2.0/bits/invoke.h:111
      (inlined by) std::_Function_handler<void (void*), networkUpTask::{lambda(void*)#1}>::_M_invoke(std::_Any_data const&, void*&&) at /Users/mat/.platformio/packages/toolchain-xtensa-esp-elf/xtensa-esp-elf/include/c++/13.2.0/bits/std_function.h:290
  #9  0x400e01b5 in std::function<void (void*)>::operator()(void*) const at /Users/mat/.platformio/packages/toolchain-xtensa-esp-elf/xtensa-esp-elf/include/c++/13.2.0/bits/std_function.h:591
      (inlined by) Mycila::Task::_run(long long const&) at .pio/libdeps/dev/MycilaTaskManager/src/MycilaTaskManager.cpp:417
  #10 0x400e0440 in Mycila::Task::tryRun() at .pio/libdeps/dev/MycilaTaskManager/src/MycilaTaskManager.cpp:334
  #11 0x400e0481 in Mycila::TaskManager::loop() at .pio/libdeps/dev/MycilaTaskManager/src/MycilaTaskManager.cpp:106
  #12 0x400e04a5 in Mycila::TaskManager::_asyncTaskManager(void*) at .pio/libdeps/dev/MycilaTaskManager/src/MycilaTaskManager.cpp:196
  #13 0x4008cefe in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:139

Another app:

[  2797][I][ESPCONNECT][1][y-pio] Set WiFi Static IP Configuration:
[  2798][I][ESPCONNECT][1][y-pio]  - IP: 192.168.[  2867][V][STA.cpp:184] _onStaEvent(): STA Started
125.99
[  2814][I][ESPCONNECT][1][y-pio]  - Gateway: 192.168.125.1
[  2814][I][ESPCONNECT][1][y-pio]  - Subnet: 255.255.255.0
[  2824][I][ESPCONNECT][1][y-pio]  - DNS: 192.168.125.1
[  2901][V][NetworkEvents.cpp:113] _checkForEvent(): Network Event: 110 - STA_START
[  2910][V][STA.cpp:110] _onStaArduinoEvent(): Arduino STA Event: 110 - STA_START
[  2850][D][ESPCONNECT][1][y-pio] Connecting to SSID: IoT...
[  2854][D][ESPCONNECT][1][y-pio] WiFi started.
[  3312][I][YASOLR][1][y-core] Starting Thyristor with semi-period: 10000 us
[  3314][I][DIMMER][1][y-core] Enable Dimmer on pin 25 with semi-period 10000 us
[  3405][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type GPIO (1) successfully set to 0x401dd584
[  3420][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 25 successfully set to type GPIO (1) with bus 0x1a
[  3352][I][DIMMER][1][y-core] Enable Dimmer on pin 26 with semi-period 10000 us
[  3432][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type GPIO (1) successfully set to 0x401dd584
[  3452][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 26 successfully set to type GPIO (1) with bus 0x1b
[  5359][V][STA.cpp:204] _onStaEvent(): STA Connected: SSID: IoT, BSSID: 00:17:13:37:28:c0, Channel: 11, Auth: OPEN
[  5372][V][NetworkEvents.cpp:113] _checkForEvent(): Network Event: 112 - STA_CONNECTED
[  5372][V][NetworkInterface.cpp:78] _onIpEvent(): sta Got New IP: 192.168.125.99 MASK: 255.255.255.0 GW: 192.168.125.1
[  5393][V][STA.cpp:110] _onStaArduinoEvent(): Arduino STA Event: 112 - STA_CONNECTED
[  5401][V][NetworkEvents.cpp:113] _checkForEvent(): Network Event: 115 - STA_GOT_IP
[  5410][V][STA.cpp:110] _onStaArduinoEvent(): Arduino STA Event: 115 - STA_GOT_IP
[  5418][V][STA.cpp:169] _onStaArduinoEvent(): STA IP: 192.168.125.99, MASK: 255.255.255.0, GW: 192.168.125.1
[  5302][D][ESPCONNECT][1][arduino_events] [NETWORK_CONNECTING] WiFiEvent: ARDUINO_EVENT_WIFI_STA_GOT_IP
[  5307][D][ESPCONNECT][1][arduino_events] State: NETWORK_CONNECTING => NETWORK_CONNECTED
[  5317][D][YASOLR][1][arduino_events] NetworkState: NETWORK_CONNECTING => NETWORK_CONNECTED
[  5328][I][YASOLR][1][arduino_events] Connected with IP address 192.168.125.99
[  5403][I][YASOLR][1][y-pio] Enable Network Services
[  5404][I][YASOLR][1][y-pio] Enable Web Server
[  5533][I][AsyncTCP.cpp:62] _start_asyncsock_task(): Creating asyncTcpSock task running in core 1 (-1 for any available core)...
[  5431][I][YASOLR][1][y-pio] Enable NTP

assert failed: sntp_setoperatingmode /IDF/components/lwip/lwip/src/apps/sntp/sntp.c:728 (Required to lock TCPIP core functionality!)


Backtrace: 0x400835f9:0x3ffd7cc0 0x4008f099:0x3ffd7ce0 0x4009558a:0x3ffd7d00 0x4012ac0c:0x3ffd7e30 0x40116492:0x3ffd7e50 0x4010272f:0x3ffd7ec0 0x400ef37a:0x3ffd7f20 0x400ef441:0x3ffd7f60 0x4010582a:0x3ffd7f80 0x40105aec:0x3ffd7fb0 0x40105b2d:0x3ffd7fe0 0x40105b51:0x3ffd8000 0x4008fad2:0x3ffd8020
  #0  0x400835f9 in panic_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/panic.c:463
  #1  0x4008f099 in esp_system_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/port/esp_system_chip.c:92
  #2  0x4009558a in __assert_func at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/assert.c:80
  #3  0x4012ac0c in sntp_setoperatingmode at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/apps/sntp/sntp.c:729 (discriminator 1)
  #4  0x40116492 in configTime at /Users/mat/.platformio/packages/framework-arduinoespressif32@src-e589a26bbeefbfd0fcf50e49e574e2c6/cores/esp32/esp32-hal-time.c:53
  #5  0x4010272f in Mycila::NTPClass::sync(char const*, unsigned char) at .pio/libdeps/pro-esp32/MycilaNTP/src/MycilaNTP.cpp:66 (discriminator 1)
  #6  0x400ef37a in networkConfigTask::{lambda(void*)#1}::operator()(void*) const at src/tasks/Network.cpp:26 (discriminator 4)
  #7  0x400ef441 in void std::__invoke_impl<void, networkConfigTask::{lambda(void*)#1}&, void*>(std::__invoke_other, networkConfigTask::{lambda(void*)#1}&, void*&&) at /Users/mat/.platformio/packages/toolchain-xtensa-esp-elf/xtensa-esp-elf/include/c++/13.2.0/bits/invoke.h:61
      (inlined by) std::enable_if<is_invocable_r_v<void, networkConfigTask::{lambda(void*)#1}&, void*>, void>::type std::__invoke_r<void, networkConfigTask::{lambda(void*)#1}&, void*>(networkConfigTask::{lambda(void*)#1}&, void*&&) at /Users/mat/.platformio/packages/toolchain-xtensa-esp-elf/xtensa-esp-elf/include/c++/13.2.0/bits/invoke.h:111
      (inlined by) std::_Function_handler<void (void*), networkConfigTask::{lambda(void*)#1}>::_M_invoke(std::_Any_data const&, void*&&) at /Users/mat/.platformio/packages/toolchain-xtensa-esp-elf/xtensa-esp-elf/include/c++/13.2.0/bits/std_function.h:290
  #8  0x4010582a in std::function<void (void*)>::operator()(void*) const at /Users/mat/.platformio/packages/toolchain-xtensa-esp-elf/xtensa-esp-elf/include/c++/13.2.0/bits/std_function.h:591
      (inlined by) Mycila::Task::_run(long long const&) at .pio/libdeps/pro-esp32/MycilaTaskManager/src/MycilaTaskManager.cpp:417
  #9  0x40105aec in Mycila::Task::tryRun() at .pio/libdeps/pro-esp32/MycilaTaskManager/src/MycilaTaskManager.cpp:334
  #10 0x40105b2d in Mycila::TaskManager::loop() at .pio/libdeps/pro-esp32/MycilaTaskManager/src/MycilaTaskManager.cpp:106
  #11 0x40105b51 in Mycila::TaskManager::_asyncTaskManager(void*) at .pio/libdeps/pro-esp32/MycilaTaskManager/src/MycilaTaskManager.cpp:196
  #12 0x4008fad2 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:139

Sketch

N/A

Debug Message

N/A

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@mathieucarbou mathieucarbou added the Status: Awaiting triage Issue is waiting for triage label Oct 25, 2024
@mathieucarbou
Copy link
Contributor Author

mathieucarbou commented Oct 26, 2024

I suspect this is caused by: CONFIG_LWIP_CHECK_THREAD_SAFETY being activated ? See:

https://github.com/espressif/esp-idf/blob/release/v5.3/components/lwip/port/include/lwipopts.h#L53-L55

As I understand, CONFIG_LWIP_CHECK_THREAD_SAFETY will fail if we do not properly lock ?

That is not a bad check per see, but right now, activating it could break a lof of downstream projects, but also Arduino components right ? Example of the stack trace above, which lies in the sntp feature.

Example:

https://github.com/espressif/esp-lwip/blob/f150e2321ac09bb0fd35a7fcbc1b116fbf93434e/src/apps/sntp/sntp.c#L714

This issue seems related: #10415

@mathieucarbou
Copy link
Contributor Author

Another ref: espressif/esp-matter#853 (comment)

mathieucarbou added a commit to mathieucarbou/YaSolR that referenced this issue Oct 26, 2024
@me-no-dev
Copy link
Member

It is Matter that enabled it..

~/Desktop/ESP32/ESP-IDF-5/esp32-arduino-lib-builder/managed_components/espressif__esp_matter/connectedhomeip/connectedhomeip/config/esp32/components/chip/Kconfig:
  220              bool "Enable LwIP Thread safety options"
  221              default y
  222:             select LWIP_TCPIP_CORE_LOCKING
  223              select LWIP_CHECK_THREAD_SAFETY
  224              help
  225                  CHIP SDK performs LwIP core locking before calling an LwIP API.
  226:                 To make the calls thread safe we have to enable LWIP_TCPIP_CORE_LOCKING.
  227                  Here, we are also enabling LWIP_CHECK_THREAD_SAFETY which will assert when
  228                  LwIP code gets called from any other context or without holding the LwIP lock.

AsyncUDP in this repo is already made to work with the locks. The fastest way is to have a look and see if you can solve it yourself. Not everything in Async is executed in the LwIP thread, so some locking will now be required. We can not get rid of Matter :)

@mathieucarbou
Copy link
Contributor Author

mathieucarbou commented Oct 26, 2024

But for the last stack trace, only sntp is involved...
I am not using AsyncTCP in the second app, but AsyncTcpSock (bsd sockets).
So the bug could come from where ?

For the first stack trace, do you mean that I should port in AsyncTCP these locks like they are done in AsyncUDP ?

That's impressive the amount of libs, web servers and mqtt clients will break when they will adopt 3.1.0.

I wish AsyncTCP were included in Arduino Core !

@me-no-dev
Copy link
Member

I wish AsyncTCP were included in Arduino Core !

I do plan to do this. Seems like it will be rather sooner than later 😄

@mathieucarbou
Copy link
Contributor Author

I've placed some locks in the AsyncTCP lib, but still have some issues with sntp:

[  5494][E][AsyncTCP.cpp:1492] begin(): [AsyncTCP] LOCK_TCPIP_CORE @ .pio/libdeps/pro-esp32/AsyncTCP/src/AsyncTCP.cpp:1492
[  5515][E][AsyncTCP.cpp:1494] begin(): [AsyncTCP] UNLOCK_TCPIP_CORE @ .pio/libdeps/pro-esp32/AsyncTCP/src/AsyncTCP.cpp:1494
6m[  5386][D][YASOLR][1][y-core] No electricity detected by ZCD module
[  5534][E][AsyncTCP.cpp:1526] begin(): [AsyncTCP] LOCK_TCPIP_CORE @ .pio/libdeps/pro-esp32/AsyncTCP/src/AsyncTCP.cpp:1526
[  5546][E][AsyncTCP.cpp:1529] begin(): [AsyncTCP] UNLOCK_TCPIP_CORE @ .pio/libdeps/pro-esp32/AsyncTCP/src/AsyncTCP.cpp:1529
[  5428][I][YASOLR][1][y-pio] Enable NTP

assert failed: sntp_setoperatingmode /IDF/components/lwip/lwip/src/apps/sntp/sntp.c:728 (Required to lock TCPIP core functionality!)


Backtrace: 0x400835fd:0x3ffd7760 0x4008f09d:0x3ffd7780 0x4009565e:0x3ffd77a0 0x4012acd0:0x3ffd78d0 0x40116556:0x3ffd78f0 0x4010276f:0x3ffd7960 0x400ef37e:0x3ffd79c0 0x400ef445:0x3ffd7a00 0x4010586a:0x3ffd7a20 0x40105b2c:0x3ffd7a50 0x40105b6d:0x3ffd7a80 0x40105b91:0x3ffd7aa0 0x4008fba6:0x3ffd7ac0
  #0  0x400835fd in panic_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/panic.c:463
  #1  0x4008f09d in esp_system_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/port/esp_system_chip.c:92
  #2  0x4009565e in __assert_func at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/assert.c:80
  #3  0x4012acd0 in sntp_setoperatingmode at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/apps/sntp/sntp.c:729 (discriminator 1)
  #4  0x40116556 in configTime at /Users/mat/.platformio/packages/framework-arduinoespressif32@src-e589a26bbeefbfd0fcf50e49e574e2c6/cores/esp32/esp32-hal-time.c:53
  #5  0x4010276f in Mycila::NTPClass::sync(char const*, unsigned char) at .pio/libdeps/pro-esp32/MycilaNTP/src/MycilaNTP.cpp:66 (discriminator 1)

@mathieucarbou
Copy link
Contributor Author

Ok so I've fixed AsyncTCP in mathieucarbou/AsyncTCP#28:

Tested :

  • I can spawn 16 concurrent client connection without issue
  • I can spawn 16 concurrent requests (tested with ESPASyncWS)

image

The only issue now remains sntp, and I have no control over that.

Is it a bug in Arduino Core ?

configTime at /Users/mat/.platformio/packages/framework-arduinoespressif32@src-e589a26bbeefbfd0fcf50e49e574e2c6/cores/esp32/esp32-hal-time.c:53

assert failed: sntp_setoperatingmode /IDF/components/lwip/lwip/src/apps/sntp/sntp.c:728 (Required to lock TCPIP core functionality!)


Backtrace: 0x400835fd:0x3ffd7760 0x4008f09d:0x3ffd7780 0x4009565e:0x3ffd77a0 0x4012acd0:0x3ffd78d0 0x40116556:0x3ffd78f0 0x4010276f:0x3ffd7960 0x400ef37e:0x3ffd79c0 0x400ef445:0x3ffd7a00 0x4010586a:0x3ffd7a20 0x40105b2c:0x3ffd7a50 0x40105b6d:0x3ffd7a80 0x40105b91:0x3ffd7aa0 0x4008fba6:0x3ffd7ac0
  #0  0x400835fd in panic_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/panic.c:463
  #1  0x4008f09d in esp_system_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/port/esp_system_chip.c:92
  #2  0x4009565e in __assert_func at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/assert.c:80
  #3  0x4012acd0 in sntp_setoperatingmode at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/apps/sntp/sntp.c:729 (discriminator 1)
  #4  0x40116556 in configTime at /Users/mat/.platformio/packages/framework-arduinoespressif32@src-e589a26bbeefbfd0fcf50e49e574e2c6/cores/esp32/esp32-hal-time.c:53
  #5  0x4010276f in Mycila::NTPClass::sync(char const*, unsigned char) at .pio/libdeps/pro-esp32/MycilaNTP/src/MycilaNTP.cpp:66 (discriminator 1)

mathieucarbou added a commit to mathieucarbou/AsyncTCP that referenced this issue Oct 26, 2024
@NicoWallmeier
Copy link

From my point of view the sntp bug is a Arduino Core bug.

As a workaround I modified my sources in the following way:

#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING
        if (!sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER))
            LOCK_TCPIP_CORE();
#endif
        configTzTime(m_timeZone.c_str(), m_ntpServer.c_str());
#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING
        if (sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER))
            UNLOCK_TCPIP_CORE();
#endif

My sketch is running fine now with Arduino Core 3.1.0-rc2, the mentioned workaround and the fix in AsyncTCP...

@mathieucarbou
Copy link
Contributor Author

mathieucarbou commented Oct 26, 2024

I have applied this patch in https://github.com/mathieucarbou/MycilaNTP and I confirm it works too.

mathieucarbou added a commit to mathieucarbou/MycilaNTP that referenced this issue Oct 26, 2024
mathieucarbou added a commit to mathieucarbou/YaSolR that referenced this issue Oct 26, 2024
@me-no-dev
Copy link
Member

can you please post a patch to the AsyncTCP repo and the ntp one to this repo? I will merge them asap

@mathieucarbou
Copy link
Contributor Author

For NTP, yes, will do later.

For AsyncTCP, it is done: https://github.com/mathieucarbou/AsyncTCP.

I don't see the point in sending PRs to the original repo, except if there is a clear motivation to "resurrect" it and keep it alive and maintained, with a few collaborators added in the project, who can also deploy to registries (Arduino and Pio).

FYI the diff with original repo

There has been many fixes / improvements from ESPHome, community and me. At any point these can be merge back to the original repo.

@microfoundry
Copy link

microfoundry commented Oct 26, 2024

I caught this one while chasing a system crash for a different issue. This is with Mathieu's updated AsyncTCP. The scenario is a simple EspAsyncWebServer (Mathieu's too) webserver/websockets with page data deliver via websockets. And in this case, an iPhone opened webpage (via Chrome) the page has stats delivered via websocket, but is not a page designed to be continually refreshed. The ws.cleanupClients() is being called and the following occured when the iPhone finally hits the auto-lock timeout. No additional investigation has been performed.

assert failed: tcp_arg /IDF/components/lwip/lwip/src/core/tcp.c:2031 (Required to lock TCPIP core functionality!)

0x40376932: panic_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/panic.c line 463
0x4037f0d9: esp_system_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/port/esp_system_chip.c line 92
0x4037f0d9: esp_system_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/port/esp_system_chip.c line 92
0x40385ccd: __assert_func at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/assert.c line 80
0x40385ccd: __assert_func at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/assert.c line 80
0x42061555: tcp_arg at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/tcp.c line 2031
0x42061555: tcp_arg at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/tcp.c line 2031
0x4203094d: AsyncClient::_error(signed char) at c:\Users\TerryPhillips\Documents\Arduino\libraries\AsyncTCP\src\AsyncTCP.cpp line 954
0x42030d33: _async_service_task(void*) at c:\Users\TerryPhillips\Documents\Arduino\libraries\AsyncTCP\src\AsyncTCP.cpp line 1414
0x4037fe52: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c

@mathieucarbou
Copy link
Contributor Author

@microfoundry : good catch! Indeed I forgot this one:
https://github.com/mathieucarbou/AsyncTCP/blob/main/src/AsyncTCP.cpp#L954
I will fix tomorrow morning and issue a new release.

@mathieucarbou
Copy link
Contributor Author

mathieucarbou commented Oct 26, 2024

@me-no-dev @NicoWallmeier : fyi PR opened for the sntp fix

@mathieucarbou
Copy link
Contributor Author

@microfoundry : I have released AsyncTCP v3.2.12. Please let me know if you encounter other issues. It is still possible that some other code path need locking but I cannot find them right now.

@Nezaemmy
Copy link

on my code I got this error

assert failed: sntp_stop /IDF/components/lwip/lwip/src/apps/sntp/sntp.c:696 (Required to lock TCPIP core functionality!)

I used these libraries

#include "time.h"
#include "esp_sntp.h"

@mathieucarbou
Copy link
Contributor Author

on my code I got this error

assert failed: sntp_stop /IDF/components/lwip/lwip/src/apps/sntp/sntp.c:696 (Required to lock TCPIP core functionality!)

I used these libraries

#include "time.h" #include "esp_sntp.h"

If you are not using the Arduino API you need to lock yourself the calls to sntp_* like I did: https://github.com/espressif/arduino-esp32/pull/10529/files

@microfoundry
Copy link

@microfoundry : I have released AsyncTCP v3.2.12. Please let me know if you encounter other issues. It is still possible that some other code path need locking but I cannot find them right now.

Thank you @mathieucarbou - that resolved the issue

@me-no-dev
Copy link
Member

@mathieucarbou it's up to you wether you will send a PR to the original repo. It's up to me wether will be "resurrected", but your ways do leave me wandering many things...

@mathieucarbou
Copy link
Contributor Author

but your ways do leave me wandering many things...

If something is bothering you, you can tell me ;-)
If something is bothering me, I will tell you (and I did, like above).
Transparency is key, this is OSS, and we all work for the main benefits of others.
So if you see something wrong to improve, please explain :-)

I just said I cannot afford to spend my little spare time sending a PR to fix all the projects I am not using, cannot use or cannot maintain, which is totally understandable. I would be glad to merge all the changes of my fork back to the original AsyncTCP repo though, but for me to spend time here, I don't want it to be for nothing and I would do it if there's a plan to add collaborators to the project, CI, deployment and also time allocated for maintenance, review, pr merge, etc. Things that I am able to do in my fork for now.

@me-no-dev
Copy link
Member

I would be glad to merge all the changes of my fork back to the original AsyncTCP repo

That would be great.

if there's a plan to add collaborators to the project, CI, deployment and also time allocated for maintenance, review, pr merge, etc.

Plan is to add it directly to the core and be fully supported here. I have not decided on the WebServer yet, but the TCP should be here, just like UDP. I do have some fun plans for it's future also.

@sivar2311
Copy link
Contributor

Now I'm getting off-topic, but I can't resist:

I have not decided on the WebServer yet, but the TCP should be here, just like UDP. I do have some fun plans for it's future also.

Please also consider AsyncWebServer for this!
It would be great to have an updated and maintained version of this masterpiece!

@mathieucarbou
Copy link
Contributor Author

I would be glad to merge all the changes of my fork back to the original AsyncTCP repo

That would be great.

if there's a plan to add collaborators to the project, CI, deployment and also time allocated for maintenance, review, pr merge, etc.

Plan is to add it directly to the core and be fully supported here. I have not decided on the WebServer yet, but the TCP should be here, just like UDP. I do have some fun plans for it's future also.

Ok! I will put that on my list and will do it then. Fist need to finish other things but I will for sure have time to do it before the end of the year.

@microfoundry
Copy link

Going to kick this one again with:

assert failed: tcp_close_ext /IDF/components/lwip/lwip/src/core/tcp.c:492 (Required to lock TCPIP core functionality!)

0x4037f0d9: esp_system_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/port/esp_system_chip.c line 92
0x40385ccd: __assert_func at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/assert.c line 80
0x42065aa6: tcp_close_ext at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/tcp.c line 492
0x42065ad5: tcp_close at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/tcp.c line 486
0x42033b40: AsyncServer::end() at c:\Users\TerryPhillips\Documents\Arduino\libraries\AsyncTCP\src\AsyncTCP.cpp line 1535
0x4203b4c1: AsyncWebServer::end() at c:\Users\TerryPhillips\Documents\Arduino\libraries\ESP_Async_WebServer\src\WebServer.cpp line 124

@mathieucarbou
Copy link
Contributor Author

mathieucarbou commented Nov 12, 2024

Going to kick this one again with:

assert failed: tcp_close_ext /IDF/components/lwip/lwip/src/core/tcp.c:492 (Required to lock TCPIP core functionality!)

0x4037f0d9: esp_system_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/port/esp_system_chip.c line 92
0x40385ccd: __assert_func at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/assert.c line 80
0x42065aa6: tcp_close_ext at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/tcp.c line 492
0x42065ad5: tcp_close at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/tcp.c line 486
0x42033b40: AsyncServer::end() at c:\Users\TerryPhillips\Documents\Arduino\libraries\AsyncTCP\src\AsyncTCP.cpp line 1535
0x4203b4c1: AsyncWebServer::end() at c:\Users\TerryPhillips\Documents\Arduino\libraries\ESP_Async_WebServer\src\WebServer.cpp line 124

I've mistakenly copy pasted and set the unlock at the wrong place 😓 Fixing...

edit

=> v3.2.14

@morcibacsi
Copy link

Sorry for reviving this, but @mathieucarbou can you release a new version of ESPAsyncWebServer which uses v3.2.14 of AsyncTCP? Now we need to manually add the reference.

@mathieucarbou
Copy link
Contributor Author

Sorry for reviving this, but @mathieucarbou can you release a new version of ESPAsyncWebServer which uses v3.2.14 of AsyncTCP? Now we need to manually add the reference.

done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting triage Issue is waiting for triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants