Open vladak opened 1 year ago
Though Espressif has fixed and closed a number of storage leak bugs related to repeated esp_wifi_init()
and esp_wifi_deinit()
calls, it appears there is at least one leak still present: see https://github.com/espressif/esp-idf/issues/8446, particularly https://github.com/espressif/esp-idf/issues/8446#issuecomment-1400780650, which describes a scenario similar to what we do.
CircuitPython version
Code/REPL
Behavior
When
wifi.connect()
fails withConnectionError
repeatedly, it will eventually result inMemoryError
raised whenimport wifi
is done. This looks like a resource leak.To reproduce this, one would need to simulate WiFi problems somehow (possibly use non-existent SSID, although I have not tried this). In my case the exception report goes like this:
publish()
fails withMMQTTException: No data received from broker for 10 seconds.
I guess this is when the WiFi flakiness of the microcontroller takes place. As a resultsupervisor.reload()
is done.wifi.connect()
fails withConnectionError: No network with that ssid
. Anothersupervisor.reload()
is done. This is repeated some 27 times.MemoryError: Failed to allocate Wifi memory
is thrown which stops the microcontroller finally because this exception is not handled in the code (because it happens in the global scope, not withinmain()
). The QtPy will start flashing the LED diode twice with red color, every 5 seconds.In reality this happens with https://github.com/vladak/shield/blob/master/code.py however I don't think the rest of the code matters. Maybe some data need to be sent over the WiFi in order to enter the state when it fails to work even after
supervisor.reload()
.When this happens, other microcontrollers (ESP32 based Feathers and QtPy's) on the same WiFi network have no trouble communicating with the MQTT broker.
Description
I am filing this issue for the resource leak, however I suspect there is another problem that leads to the unrecoverable WiFi flakiness. It could be a firmware or HW issue as I don't see this on identical (both SW and HW wise) QtPy.
Additional information
See https://github.com/vladak/shield/issues/13 for complete log of the program and proposed ways to workaround this.