WiFi (specifically WifiGeneric) handling of events is subject to race conditions #6947
Open
1 task done
Labels
Area: BT&Wifi
BT & Wifi related issues
Type: Documentation
Issue pertains to Documentation of Arduino ESP32
Type: For reference
Common questions & problems
Board
any board (with networking)
Device Description
any device (with networking)
Hardware Configuration
no special configuration
Version
latest development Release Candidate (RC-X)
IDE Name
any IDE
Operating System
any OS
Flash frequency
any frequency
PSRAM enabled
yes
Upload speed
any speed
Description
It's hard to write a specific repro case for this since it depends on race conditions. (Also, my understanding may be off, please correct!)
The
WiFi
instance allows user code to register for events withWiFi.onEvent()
. This isn't documented, but it is present in most example code, described in various tutorials and copied into many/most network-using sketches. This is implemented theWiFiGeneric
class (one of the base classes forWiFiClass
, of whichWiFi
is an instance) using an independently running FreeRTOS task (pinned to core 0(?) by default):arduino-esp32/libraries/WiFi/src/WiFiGeneric.cpp
Line 299 in fcd4799
That free-running task reads from a queue and invokes
WiFiGenericClass::_eventCallback()
:arduino-esp32/libraries/WiFi/src/WiFiGeneric.cpp
Line 924 in fcd4799
After translating the event,
_eventCallback()
loops through all registered callbacks and invokes them serially:arduino-esp32/libraries/WiFi/src/WiFiGeneric.cpp
Line 1049 in fcd4799
Nowhere in this process is locking or other synchronization done, that I can figure out. I see these implications?
cbEventList
. Most code will add callbacks at the start and leave them there forever, but if that's the expectation it seems worth documenting?(Hopefully you'll tell me why this is all wrong and secretly it's all serialized so the callbacks only happen between calls to
loop()
or something like that...?)Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: