wifi: esp_at: race condition on mutex's leading to deadlock #43470
Labels
area: Sockets
Networking sockets
area: Wi-Fi
Wi-Fi
bug
The issue is a bug, or the PR is fixing a bug
LTS
Long term release branch related
platform: ESP32
Espressif ESP32
priority: low
Low impact/importance bug
Describe the bug
The send and receive code paths for Zephyr sockets when using the ESP AT command WiFi driver claim the same two mutex's in different orders. This leads to a permanent deadlock when you get unlucky with packet timings.
When receiving
The ESP RX thread claims the socket mutex before calling into the Zephyr socket library.
zephyr/drivers/wifi/esp_at/esp_socket.c
Lines 172 to 174 in c32d10c
zsock_received_cb
then claims the net_context mutex.zephyr/subsys/net/lib/sockets/sockets.c
Lines 361 to 369 in c32d10c
When transmitting
zsock_send_message
claims the net_context mutex (insidenet_context_sendmsg
).zephyr/subsys/net/ip/net_context.c
Lines 1788 to 1799 in c32d10c
esp_socket_queue_tx
then claims the socket mutex.zephyr/drivers/wifi/esp_at/esp.h
Lines 364 to 369 in c32d10c
Expected behavior
Mutex's should be claimed in the same order in all code paths to avoid deadlock.
Impact
WiFi driver is permanently unusable until the application is power cycled.
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: