loboris / ESP32_TFT_library

Full featured TFT library for ESP32 with demo application
553 stars 219 forks source link

multithread + garbage collection + socket causes CPU halt #61

Closed taitix closed 5 years ago

taitix commented 5 years ago

When I use microWebSrv+microWebSocket, Guru Meditation (LoadProhibited) occurs when automatic GC runs or manually run gc.collect(). I wrote a minimal code to reproduce the issue which ended up in assertion failure which happend only in try statement within a function. (I'm not sure if this is causing the Guru Meditaion (LoadProhibited) though...)

from time import sleep_ms
import machine, socket, gc, _thread
from network import WLAN, STA_IF

wlan = WLAN(STA_IF)
wlan.active(True)
wlan.connect('SSID', 'PASSWORD')
while not wlan.isconnected():
  sleep_ms(100)
  print('.', end='')

def gc_thread():
  while True:
    sleep_ms(10)
    gc.collect()

_thread.start_new_thread('GUI', gc_thread, ())

s = socket.socket(socket.AF_INET,
                         socket.SOCK_STREAM,
                         socket.IPPROTO_TCP)
s.bind(('0.0.0.0', 80))
s.listen(1)
s.settimeout(0.1)

# This block runs fine
try:
  client, cliAddr = s.accepted()
except Exception as e:
  print(e)

def f1(s):
  client, cliAddr = s.accepted()

def f2(s):
  try:
    client, cliAddr = s.accepted()
  except Exception as e:
    print(e)

f1(s) # this is fine
print("i'm still alive!")
f2(s) # <- calling this causes following:
# assertion "ATB_GET_KIND(block) == AT_HEAD" failed: file "/home/LoBo2_Razno/ESP32/MicroPython/MicroPython_ESP32_psRAM_LoBo/MicroPython_BUILD/components/micropython/py/gc.c", line 596, function: gc_free
# abort() was called at PC 0x4012bb07 on core 1
#
# Backtrace: 0x40095bcc:0x3ffc60d0 0x40095d93:0x3ffc60f0 0x4012bb07:0x3ffc6110 0x400ed38e:0x3ffc6140 0x400ecb55:0x3ffc6160 0x400fa919:0x3ffc6180 0x400f5acd:0x3ffc61b0 0x40103e07:0x3ffc61d0 0x400fa8da:0x3ffc6270 0x400f5acd:0x3ffc62a0 0x400f5afa:0x3ffc62c0 0x400e56e3:0x3ffc62e0 0x400e5999:0x3ffc6390 0x400d7f42:0x3ffc63b0
# CPU halted.
taitix commented 5 years ago

Ah, I'm so sorry. I wanted to post this to MicroPython_ESP32_psRAM_LoBo....