adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.11k stars 1.22k forks source link

ESP32 `supervisor.reload()` does not disconnect user-connected wifi #9177

Open bill88t opened 7 months ago

bill88t commented 7 months ago

CircuitPython version

Adafruit CircuitPython 9.0.0-beta.0-52-g6c1e34e957 on 2024-02-17; M5Stack Timer Camera X with ESP32

Code/REPL

Adafruit CircuitPython 9.0.0-beta.0-52-g6c1e34e957 on 2024-02-17; M5Stack Timer Camera X with ESP32
>>> import wifi
>>> wifi.radio.connected
False
>>> wifi.radio.connect("Lunchbox", "[REDACTED]")
>>> wifi.radio.connected
True
>>> # I pressed Ctrl + D here.
soft reboot

Auto-reload is off.
Running in safe mode! Not running saved code.

You are in safe mode because:
The `microcontroller` module was used to boot into safe mode.
Press reset to exit safe mode.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 9.0.0-beta.0-52-g6c1e34e957 on 2024-02-17; M5Stack Timer Camera X with ESP32
>>> import wifi
>>> wifi.radio.connected
False
>>> wifi.radio.connect("Lunchbox", "[REDACTED]")
>>> wifi.radio.connected
True
>>> import supervisor
>>> supervisor.reload()
soft reboot

Auto-reload is off.
Running in safe mode! Not running saved code.

You are in safe mode because:
The `microcontroller` module was used to boot into safe mode.
Press reset to exit safe mode.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 9.0.0-beta.0-52-g6c1e34e957 on 2024-02-17; M5Stack Timer Camera X with ESP32
>>> import wifi
>>> wifi.radio.connected
True
>>>

Behavior

Wifi should have been disconnected, it was not. This is an issue because the socket binds are not cleared and the code fails with address in use errors.

Description

This only happens on plain ESP32 as far as I can tell. I can't repro on s2.

Additional information

This assumes no wifi auto-connect credentials are installed. I used safemode just cause it won't run my code.

dhalbert commented 2 months ago

We discussed whether this should happen deliberately or not. The web workflow is available even on user connection. Someone might start using, kind of like user-initiated displays, which stick around past the VM finishing.

bill88t commented 2 months ago

Well, this isn't linked to web workflow as it wasn't enabled at all. Having wifi stay connected is fine, but it should be at least consistent.