-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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] [release/v4.4] LoadProhibited in esp_wifi/src/wifi_netif.c:110, when switching from STA to AP (IDFGH-7092) #8702
Comments
Is there any code with a working example of switching between APSTA and STA modes? What I've tried:
ESP-IDF should really have a "WifiSwitching" example that is maintained and tested with HTTP, MDNS, etc. |
Edit: I've tried everything. Deinitializing everything in reverse.., wifi, netif destroy, event loop, mdns, http server, all the way back to blank slate and then reinitializing. But still bugs. hit new crashes in ESP-IDF code after switching a couple times (PC 0x400553b6, corrupted backtrace), but even without the crash my phone still refuses to connect to the AP. DHCP seems to just not work after switching. My advice: switching wifi modes should be avoided. I have no confidence it will work reliably even if I got it to work. It's does not seem to be tested by Espressif. Edit2: I fixed the non-connection issue. It was a stupid mistake. I had 2 devices both advertising the same mdns hostname by mistake and never realized it. I unplugged the other device and mdns started working. If you aren't using MDNS, HTTP, etc, maybe you can get away with it. But for anything more complicated, wifi switching is a mountain of pain. |
Are you using esp_netif_new() when you're switching ? They had a similar problem caused by esp_netif_init() when called mutliple times. |
Yes. My understanding is the esp_netif_new() is called when I call esp_netif_create_default_wifi_ap(). From my above logs:
|
Of course, worth reiterating that this crash should still be fixed and replaced with a log + err code if something is called incorrectly. Hopefully my logs + esp-idf code inspection are enough to find and fix it. |
Could you please try to call The init-deinit sequence is being tested, not very thoroughly though, for example here:
|
Crashes. No backtrace =/
|
@chipweinberger Please refer to a very simple example which repeatably creates and destroys wifi in STA mode and AP+STA mode in turn. This works okay on my side. https://gist.github.com/david-cermak/612487bc96df8a4dd56610d97b20dc3d I noticed, that you also run mdns and SNTP client on some interfaces. Please note that these modules have to be properly deininitalized, separately; calling |
Really appreciate you trying to replicate this crash. It's good to know it works for you and appreciate your example code! That code will be very useful for other users in the future. I did not know that SNTP also has to be deinitialized, it is possible that is causing the later crash I experienced after the 2nd wifi switch. Your code convinces me it seems possible to get this to work. At the moment I changed my code to just reboot, which seems a lot easier heh. Perhaps with SNTP deinit this will start working. It seems worthwhile for Espressif to maintain an example that uses all of the web stack (http, mdns, sntp, etc), and successfully preforms a wifi switch. It's very nontrivial! =) and probably will easily be broken unless tested. Your code seems like a good starting point for such an example. |
Updated the gist to use SNTP
this is very easy, just run
Good idea. I agree that it's not very straight-forward to correctly deinit a module. What usually helps is to look at the unit tests of these components, as almost all have a simple init-deinit case (e.g. the one for |
Thanks ❤️
The bigger issue is much higher level imo. how all the pieces fit together.
this code is complicated but important enough to warrant an example. to figure out 1 and 2 I basically had to spend a day guessing and checking. |
The rule of thumb is that if the module uses "some specific" network interface it should be deinitialized before destroying the underlying esp-netif. For example HTTP server doesn't have to, unless it's bound to a specific netif.
Here, it's also quite simple IMO, the higher layered module should be initialized after the lower layered, and deinited before the lower layered. (saw that I made a mistake in my gist, shouldve deinited sntp 2 lines before)
Agree that an example would be useful, but it wouldn't cover all usecases, or all options we have. e.g. in your case, I think you don't have to deinitialize the network at all when switching from STA to AP+STA, you could simply reuse the esp-netif handle. But you need a separate handle for the station interface and one for the AP interface. |
Appreciate all the information. If not an example, perhaps a dedicated documentation page on Wifi Switching? I hate to think all this useful information will be hard to find! It would be especially useful for newer users =) Wifi switching should be made easy! For the original crash this issue was filed for, feel free to close this issue if you don't think there is enough to go on. I think with code inspection there might be enough info to find it. It looks like a null dereference here:
Again, appreciate you helping! Launching a product this year =) |
Bump. @david-cermak, is this worth investigating for you? If not, feel free to close. My last comment has as much detail as I can provide. It may or may not be enough to go on. |
An easy and IMO still "proper" solution, given that we already return an error, return INVALID_ARG:
And might as well do the same for these:
Arguably, to be consistently "null safe", we should make every function handle NULL. It is pretty obvious that a NULL pointer is not "ready".
|
awesome. thanks David! |
Added null pointer checks to WiFi-netif API functions to prevent potential crashes from invalid arguments, updated unit tests. Closes #8702
Added null pointer checks to WiFi-netif API functions to prevent potential crashes from invalid arguments, updated unit tests. Closes #8702
Added null pointer checks to WiFi-netif API functions to prevent potential crashes from invalid arguments, updated unit tests. Closes #8702
ESP32-S3
ESP-IDF release/v4.4 (c29343e) from a few days ago.
Been trying to get AP -> APSTA mode switching working. Hit a crash in ESP-IDF.
netif or esp_wifi does not appear to be cleaning up after itself correctly. See the logs. My Logs make it clear how I am calling ESP-IDF code.
Logs:
The text was updated successfully, but these errors were encountered: