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 tcp server in >B or >BS section #21654

Closed
12 of 14 tasks
Thalhammer opened this issue Jun 18, 2024 · 2 comments · Fixed by #21660
Closed
12 of 14 tasks

Crash with tcp server in >B or >BS section #21654

Thalhammer opened this issue Jun 18, 2024 · 2 comments · Fixed by #21660

Comments

@Thalhammer
Copy link

PROBLEM DESCRIPTION

ESP crashes when wso(x) is executed in a script >B or >BS section. Delaying the initialization using a timer fixes the issue, but is obviously less then ideal. Enabling the script after boot also works, but is not ideal as well.

REQUESTED INFORMATION

Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!

  • Read the Contributing Guide and Policy and the Code of Conduct
  • Searched the problem in issues
  • Searched the problem in discussions
  • Searched the problem in the docs
  • Searched the problem in the chat
  • Device used (e.g., Sonoff Basic): bitShake SmartMeterReader-Air (ESP32-C3)
  • Tasmota binary firmware version number used: 2115e09
    • Pre-compiled
    • Self-compiled
  • Flashing tools used: Web Update followed by esp-tool for troubleshooting
  • Provide the output of command: Backlog Template; Module; GPIO 255:
09:22:34.321 CMD: Backlog Template; Module; GPIO 255
09:22:34.341 RSL: RESULT = {"NAME":"ESP32C3","GPIO":[1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1],"FLAG":0,"BASE":1}
09:22:34.569 RSL: RESULT = {"Module":{"1":"ESP32C3"}}
09:22:34.776 RSL: RESULT = {"GPIO0":{"0":"None"},"GPIO1":{"0":"None"},"GPIO2":{"0":"None"},"GPIO3":{"0":"None"},"GPIO4":{"0":"None"},"GPIO5":{"0":"None"},"GPIO6":{"0":"None"},"GPIO7":{"0":"None"},"GPIO8":{"0":"None"},"GPIO9":{"0":"None"},"GPIO10":{"0":"None"},"GPIO11":{"0":"None"},"GPIO12":{"0":"None"},"GPIO13":{"0":"None"},"GPIO18":{"0":"None"},"GPIO19":{"0":"None"},"GPIO20":{"0":"None"},"GPIO21":{"0":"None"}}
  • If using rules, provide the output of this command: Backlog Rule1; Rule2; Rule3:
Not using Rules
  • Provide the output of this command: Status 0:
09:23:53.737 CMD: Status 0
09:23:53.740 RSL: STATUS = {"Status":{"Module":1,"DeviceName":"Tasmota","FriendlyName":["Tasmota"],"Topic":"","ButtonTopic":"0","Power":"0","PowerLock":"0","PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0,"InfoRetain":0,"StateRetain":0,"StatusRetain":0}}
09:23:53.746 RSL: STATUS1 = {"StatusPRM":{"Baudrate":115200,"SerialConfig":"8N1","GroupTopic":"tasmotas","OtaUrl":"http://ota.tasmota.com/tasmota32/release/tasmota32c3.bin","RestartReason":"Software reset digital core","Uptime":"0T00:07:53","StartupUTC":"2024-06-18T07:16:00","Sleep":50,"CfgHolder":4619,"BootCount":16,"BCResetTime":"2024-06-18T08:48:36","SaveCount":33}}
09:23:53.750 RSL: STATUS2 = {"StatusFWR":{"Version":"14.1.0.2(tasmota32)","BuildDateTime":"2024-06-18T09:13:07","Core":"3_0_1","SDK":"5.1.4.240602","CpuFrequency":160,"Hardware":"ESP32-C3 v0.4","CR":"343/699"}}
09:23:53.754 RSL: STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":2,"MqttLog":0,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["<redacted>",""],"TelePeriod":15,"Resolution":"558180C0","SetOption":["00008009","2805C80001000600003C5A0A192800000000","00000080","00006000","00004000","00000000"]}}
09:23:53.765 RSL: STATUS4 = {"StatusMEM":{"ProgramSize":2079,"Free":800,"Heap":176,"StackLowMark":4,"PsrMax":0,"PsrFree":0,"ProgramFlashSize":4096,"FlashSize":4096,"FlashChipId":"164020","FlashFrequency":80,"FlashMode":"DIO","Features":["0809","979AD7DF","001DA001","B7F7BFCF","05DA9BC4","E0360DCF","480840D2","20200000","D4BC482D","810A80B1","00000015"],"Drivers":"1,2,!3,!4,!5,7,!8,9,10,11,12,!14,!16,!17,!20,!21,!24,26,!27,29,!34,!35,38,50,52,!59,!60,62,!63,!66,!67,!68,!71,!73,82,!86,!87,!88,!121","Sensors":"1,2,3,5,6,7,8,9,10,11,12,13,14,15,17,18,19,20,21,22,26,31,34,37,39,40,42,43,45,51,52,53,55,56,58,59,64,66,67,74,85,92,95,98,103,105,109,127","I2CDriver":"7,8,9,10,11,12,13,14,15,17,18,20,24,29,31,36,41,42,44,46,48,58,62,65,69,76,77,82"}}
09:23:53.772 RSL: STATUS5 = {"StatusNET":{"Hostname":"x2496","IPAddress":"<redacted>","Gateway":"<redacted>","Subnetmask":"255.255.255.0","DNSServer1":"<redacted>","DNSServer2":"0.0.0.0","Mac":"<redacted>","IP6Global":"","IP6Local":"fe80::424c:caff:fec8:c9c0%st1","Ethernet":{"Hostname":"","IPAddress":"0.0.0.0","Gateway":"0.0.0.0","Subnetmask":"0.0.0.0","DNSServer1":"<redacted>","DNSServer2":"0.0.0.0","Mac":"00:00:00:00:00:00","IP6Global":"","IP6Local":""},"Webserver":2,"HTTP_API":1,"WifiConfig":4,"WifiPower":19.0}}
09:23:53.778 RSL: STATUS6 = {"StatusMQT":{"MqttHost":"<redacted>","MqttPort":1883,"MqttClientMask":"","MqttClient":"","MqttUser":"","MqttCount":0,"MAX_PACKET_SIZE":1200,"KEEPALIVE":30,"SOCKET_TIMEOUT":4}}
09:23:53.783 RSL: STATUS7 = {"StatusTIM":{"UTC":"2024-06-18T07:23:53Z","Local":"2024-06-18T09:23:53","StartDST":"2024-03-31T02:00:00","EndDST":"2024-10-27T03:00:00","Timezone":99,"Sunrise":"<redacted>","Sunset":"<redacted>"}}
09:23:53.788 RSL: STATUS10 = {"StatusSNS":{"Time":"2024-06-18T09:23:53"}}
09:23:53.793 RSL: STATUS11 = {"StatusSTS":{"Time":"2024-06-18T09:23:53","Uptime":"0T00:07:53","UptimeSec":473,"Heap":174,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":0,"Berry":{"HeapUsed":4,"Objects":46},"Wifi":{"AP":1,"SSId":"<redacted>","BSSId":"<redacted>","Channel":6,"Mode":"HT20","RSSI":62,"Signal":-69,"LinkCount":1,"Downtime":"0T00:00:04"}}}
  • Set weblog to 4 and then, when you experience your issue, provide the output of the Console log:
ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x3 (RTC_SW_SYS_RST),boot:0xd (SPI_FAST_FLASH_BOOT)
Saved PC:0x40048b82
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5820,len:0x48
load:0x403cc710,len:0x644
load:0x403ce710,len:0x2294
entry 0x403cc710

00:00:00.001 CMD: Using USB CDC
00:00:00.001 HDW: ESP32-C3 v0.4 
00:00:00.004 UFS: FlashFS mounted with 304 kB free
00:00:00.008 CFG: Loaded from File, Count 33
00:00:00.010 SER: Set to 8N1 115200 bit/s
00:00:00.010 SER: HWCDC supports 115200 bit/s only
00:00:00.014 QPC: Count 1
00:00:00.016 SCR: ufilesystem found
00:00:00.021 SCR: nv=1, tv=0, vns=4, vmem=33, smem=8192, gmem=424, tmem=8653 
00:00:00.047 BRY: Berry initialized, RAM used 4400 bytes
00:00:00.055 Project tasmota - Tasmota Version 14.1.0.2(tasmota32)-3_0_1(2024-06-18T09:13:07)
00:00:00.056 tcp server started
Guru Meditation Error: Core  0 panic'ed (Load access fault). Exception was unhandled.

Core  0 register dump:
MEPC    : 0x420e6cd0  RA      : 0x420d6d6e  SP      : 0x3fca2020  GP      : 0x3fc8c000  
TP      : 0x3fc01d50  T0      : 0x420e6cca  T1      : 0x40387cc2  T2      : 0x00000009  
S0/FP   : 0x3fc9e7f4  S1      : 0x420e8116  A0      : 0x3fc9ac10  A1      : 0x3fca2040  
A2      : 0x3fc9e7f4  A3      : 0x00000004  A4      : 0x3fc9b000  A5      : 0x00000000  
A6      : 0x3fca1fc0  A7      : 0x00000073  S2      : 0x3fc9e7b8  S3      : 0x000001f6  
S4      : 0x00000007  S5      : 0x3fca23fc  S6      : 0x3fca4c3c  S7      : 0x3fca23f8  
S8      : 0x3fca4c3c  S9      : 0x00000000  S10     : 0x3fca23f7  S11     : 0x3fca483c  
T3      : 0x7fffffff  T4      : 0x00000000  T5      : 0x0ccccccc  T6      : 0x00000019  
MSTATUS : 0x00001881  MTVEC   : 0x40380001  MCAUSE  : 0x00000005  MTVAL   : 0x00000000  
MHARTID : 0x00000000  

Stack memory:
3fca2020: 0x3fca4c3c 0x3fca23fc 0x00000007 0x3fca2040 0x3fc9e7b8 0x420e8116 0x3fc9e7f4 0x420d6d6e
  #0  0x420e8116 in lwip_netconn_do_newconn at ??:?
  #1  0x420d6d6e in tcpip_send_msg_wait_sem at ??:?

3fca2040: 0x00000000 0x420e8116 0x3fca2078 0x420e6ec0 0x3fc9e7b8 0x420e8116 0x3fca2078 0x420e6ffe
  #0  0x420e8116 in lwip_netconn_do_newconn at ??:?
  #1  0x420e6ec0 in sys_thread_sem_get at ??:?
  #2  0x420e8116 in lwip_netconn_do_newconn at ??:?
  #3  0x420e6ffe in netconn_apimsg at api_lib.c.obj:?

3fca2060: 0x3fc9e7b8 0x00000000 0x3fca6c40 0x420e706a 0x3fc9e7b8 0x3fca49e0 0x3fca6c40 0x40389750
  #0  0x420e706a in netconn_new_with_proto_and_callback at ??:?
  #1  0x40389750 in multi_heap_free at ??:?

3fca2080: 0x3fc9e700 0x00000002 0x3fca49e0 0x403832b6 0x3fca4c3c 0x3fca23fc 0x00000007 0x3fc9e7f4
  #0  0x403832b6 in heap_caps_free at ??:?

3fca20a0: 0x3fc9e7b8 0x3fc91b08 0x3fc9e7b8 0x420d6612 0x3fc9e7b8 0x3fc91b08 0x3fc9e7b8 0x4207c334
  #0  0x420d6612 in lwip_socket at ??:?
  #1  0x4207c334 in NetworkServer::begin(unsigned short, int) at /home/dominik/.platformio/packages/framework-arduinoespressif32/libraries/Network/src/NetworkServer.cpp:81
      (inlined by) NetworkServer::begin(unsigned short) at /home/dominik/.platformio/packages/framework-arduinoespressif32/libraries/Network/src/NetworkServer.cpp:70

3fca20c0: 0x00000001 0x3fc91b08 0x3fca23f0 0x4202efbe 0x3fca2538 0x3fc91b08 0x00000004 0x4005893a
  #0  0x4202efbe in isvar(char*, unsigned char*, T_INDEX*, float*, char*, GVARS*) at tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino:6202

3fca20e0: 0x3fc9e7b8 0x3fc91b08 0x3fca23f0 0x4202efc8 0x00000000 0x000002fc 0x3fca2178 0x00000007
  #0  0x4202efc8 in NetworkServer::setNoDelay(bool) at /home/dominik/.platformio/packages/framework-arduinoespressif32/libraries/Network/src/NetworkServer.cpp:109
      (inlined by) isvar(char*, unsigned char*, T_INDEX*, float*, char*, GVARS*) at tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino:6203

3fca2100: 0x00000000 0x3fca4848 0x3fca4844 0x00000077 0x00000000 0x00000008 0x00000000 0x3fca4c43
3fca2120: 0x00000000 0x00000000 0x000000e2 0x00000001 0x00001000 0x3fca40e8 0x3fca40e8 0x00000003
3fca2140: 0x00000000 0x00000003 0x3fca4844 0x00000072 0x00000000 0xffffffff 0x00000000 0x3fca4c38
3fca2160: 0x00000010 0x00000000 0x3c1d7e6c 0x42091316 0x2ae5e1c3 0x3fca21d8 0x3c1dd370 0x4209136e
  #0  0x42091316 in _hashcode at lib/libesp32/berry/src/be_map.c:92
  #1  0x4209136e in eqnode at lib/libesp32/berry/src/be_map.c:113 (discriminator 1)

3fca2180: 0x500ffc18 0x00000004 0x3fca40e8 0x42103c86 0x3fca4870 0x3c1df3c8 0x3c1dd370 0x420913f4
  #0  0x42103c86 in lfs_dir_fetchmatch at lfs.c.obj:?
  #1  0x420913f4 in find at lib/libesp32/berry/src/be_map.c:185

3fca21a0: 0x00000011 0x00000016 0x3fca6ed0 0x3c1e1a58 0x3c1df3c8 0x3fca4870 0x3fca21d8 0x42091522
  #0  0x42091522 in be_map_find at lib/libesp32/berry/src/be_map.c:252

3fca21c0: 0x3fca4870 0x3fc9e1e8 0x3fca6ed0 0x42091542 0xc0380000 0x00000000 0x3c1e1a58 0x00000010
  #0  0x42091542 in be_map_findstr at lib/libesp32/berry/src/be_map.c:314

3fca21e0: 0x3fca4870 0x3fc9e1e8 0x3fca6ed0 0x42091570 0x00000011 0x00000016 0x3fca6ed0 0x3fca6f90
  #0  0x42091570 in instance_member at lib/libesp32/berry/src/be_class.c:139

3fca2200: 0x3fca6f98 0x3fca4870 0x3fc9e1e0 0x420911c2 0x00000011 0x00000016 0x0000000b 0x3fca6ed0
  #0  0x420911c2 in be_instance_member at lib/libesp32/berry/src/be_class.c:282

3fca2220: 0x3fca6f98 0x3fc9e1e0 0x3fca4870 0x420884bc 0x00000011 0x00000016 0x0000000b 0x00000001
  #0  0x420884bc in ins_member at lib/libesp32/berry/src/be_api.c:702

3fca2240: 0x3fc9e1c8 0x42093aee 0x3fca4870 0x4208b39e 0x3fc9e1c8 0x42093aee 0x3fca4870 0x42090e88
  #0  0x42093aee in m_findmember at lib/libesp32/berry/src/be_introspectlib.c:67
  #1  0x4208b39e in be_getmember at lib/libesp32/berry/src/be_api.c:706
  #2  0x42093aee in m_findmember at lib/libesp32/berry/src/be_introspectlib.c:67
  #3  0x42090e88 in be_execprotected at lib/libesp32/berry/src/be_exec.c:124

3fca2260: 0x00000013 0x3fca4870 0x4208ffce 0x3fca6f98 0x3fca2318 0x00ffffff 0x42090e7e 0x3fca4870
  #0  0x4208ffce in m_findmember_protected at lib/libesp32/berry/src/be_introspectlib.c:62
  #1  0x42090e7e in be_execprotected at lib/libesp32/berry/src/be_exec.c:121

3fca2280: 0x42093aee 0x3fc9e1c8 0x00000001 0x0000000b 0x00000016 0x00000011 0x00000012 0x286f7377
  #0  0x42093aee in m_findmember at lib/libesp32/berry/src/be_introspectlib.c:67

3fca22a0: 0x00323035 0x3fca2318 0x3c1738cc 0x42091316 0x45d41313 0x3fca2318 0x3c17841c 0x286f7377
  #0  0x42091316 in _hashcode at lib/libesp32/berry/src/be_map.c:92

3fca22c0: 0x00323035 0x3c1785b0 0x3c17841c 0x420913f4 0x3fca4870 0x3c1785b0 0x3c17841c 0x00736572
  #0  0x420913f4 in find at lib/libesp32/berry/src/be_map.c:185

3fca22e0: 0x00000011 0x00000016 0x3fc9dc80 0x3c1738cc 0x3c1785b0 0x3fca4870 0x3fca2318 0x43fb0000
3fca2300: 0x3fca4870 0x3fc9e1d8 0x3fc9dc80 0x42091542 0x00000010 0x3fca2388 0x3c1738cc 0x00000010
  #0  0x42091542 in be_map_findstr at lib/libesp32/berry/src/be_map.c:314

3fca2320: 0x3fca4870 0x3fc9e1d8 0x3fc9dc80 0x42091570 0x00000011 0x00000016 0x3fc9dc80 0x3c1738cc
  #0  0x42091570 in instance_member at lib/libesp32/berry/src/be_class.c:139

3fca2340: 0x3c16fffc 0x3fca4870 0x3fc9e1d8 0x42091152 0x3fca23f9 0x4214d536 0x3fca2488 0x3fca2850
  #0  0x42091152 in be_instance_member at lib/libesp32/berry/src/be_class.c:268
  #1  0x4214d536 in __ssputs_r at /builds/idf/crosstool-NG/.build/riscv32-esp-elf/src/newlib/newlib/libc/stdio/nano-vfprintf.c:179

3fca2360: 0x3fca23ac 0x00000000 0x3fca23e0 0x421473f6 0x00000011 0x00000016 0x0000000a 0x3c1ff000
  #0  0x421473f6 in _printf_common at /builds/idf/crosstool-NG/.build/riscv32-esp-elf/src/newlib/newlib/libc/stdio/nano-vfprintf_i.c:94

3fca2380: 0x3c1ff000 0x3fca25dc 0xffffffff 0x4214d536 0x3fca2488 0x3fca2850 0x3fca23e0 0x421476d4
  #0  0x4214d536 in __ssputs_r at /builds/idf/crosstool-NG/.build/riscv32-esp-elf/src/newlib/newlib/libc/stdio/nano-vfprintf.c:179
  #1  0x421476d4 in _printf_i at /builds/idf/crosstool-NG/.build/riscv32-esp-elf/src/newlib/newlib/libc/stdio/nano-vfprintf_i.c:241

3fca23a0: 0x40058c02 0x420334e4 0x3fca2420 0x3fc8c000 0x42033460 0x42033430 0x3fca2430 0x3fca483c
  #0  0x420334e4 in Run_script_sub(char const*, signed char, GVARS*) at tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino:8386
  #1  0x3fc8c000 in __global_pointer$ at ??:?
  #2  0x42033460 in Run_script_sub(char const*, signed char, GVARS*) at tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino:7521
  #3  0x42033430 in Run_script_sub(char const*, signed char, GVARS*) at tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino:7517

3fca23c0: 0x00000001 0xffffffff 0x000000fe 0x00000028 0x00000005 0x3fca2490 0x00000010 0x3fca2538
3fca23e0: 0x3fc91b68 0x00000001 0x3fca2530 0x420b27a8 0x3fca25f0 0x00000073 0x3fc91b68 0x00000000
  #0  0x420b27a8 in GetNumericArgument(char*, unsigned char, float*, GVARS*) [clone .constprop.0] at tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino:6676

3fca2400: 0x00000001 0xffffffff 0x00000000 0x3fc91b68 0x00000000 0x00000001 0xffffffff 0x00000000



ELF file SHA256: 717d4dc851561acc

Rebooting...

TO REPRODUCE

  1. Put the following script into your script window.
  2. Enable script
  3. Reboot
  4. Observe crash in serial console
  5. ESP reboots with script disabled
>D
res=0
>B
res=wso(8080)
print res=%res%

EXPECTED BEHAVIOUR

ESP boots normally and opens a tcp port.

SCREENSHOTS

N/A

ADDITIONAL CONTEXT

I tried various versions between 14.0 and develop as well as prebuilds I could find (sadly TCP_SERVER is not enabled by default), all of them crash the same way.

I also added extra log lines to the script interpreter during debugging and it seems to crash inside glob_script_mem.tcp_server->begin(); here.

While debugging I also noticed a secondary bug (however thats not my issue), that being if new WiFiServer(port) where to ever return null it would crash as well because it unconditionally references the pointer after setting the result code.

In addition theres a memory leak if a script calls wso more than once because it does not check/delete the WiFiServer instance before reassigning it.

@gemu2015
Copy link
Contributor

you may not open a tcp server or access any wifi related resources when wifi is not connected.
on a reboot this is never the case during >B
you can open the port when wifi is connected which you can check e.g during >S with 'wifis'

@Thalhammer
Copy link
Author

Thalhammer commented Jun 18, 2024

you may not open a tcp server or access any wifi related resources when wifi is not connected.

Yeah that's what I assumed (though opening it with a timer of 1s still does before the wifi is connected and works fine), however I couldn't find anything related to that in the docs and all the example scripts on the internet I found (apparently) have it working fine in >BS.

However I think the other two issues I noted in additional context are still valid.

@gemu2015 gemu2015 mentioned this issue Jun 20, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants