Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
ESP32: Hangs when reopening WiFi connection #4269
Summary: when waiting on network events, such as in a loop like:
As far as I understand it, the network background tasks never get run, so the loop never ends. This isn't as intended.
As a workaround, if
Thanks for copying this across from the old repo, and thanks @nickzoic for the following hint how to fix it:
So it works fine after a hard reset, but not after a soft reset. That really points to it being a problem with soft reset, in combination somehow with FreeRTOS scheduling. Since including a long sleep in the waiting works around the issue, this further points to an problem with soft reset and how idling works.
After some investigation I disabled threading and it fixed the problem. Then I just disabled the GIL and that also fixed the problem. Thus it's a problem with soft reset and the GIL, in combination with FreeRTOS scheduling.
In the end the fix is simply to release the GIL when deinitialising the uPy runtime, which is now done in fa50047 . This fix makes sense regardless of the issue here.
In summary: I think what was happening is that the main uPy task still had hold of the FreeRTOS mutex (corresponding to the GIL) upon soft reset and this put the uPy task on a special FreeRTOS scheduling queue (perhaps raising its priority) which prevented network events getting delivered to it after soft reset. There GIL mutex was reinitialised upon soft reset but this didn't help because FreeRTOS had no way to know that the old one was no longer used.