fix(asyncudp): Fixes and implements tcpip thread locking by HamzaHajeir · Pull Request #10415 · espressif/arduino-esp32 (original) (raw)

Description of Change

Implements and fixes TCPIP Core locking in AsyncUDP when enabled.

AsyncUDP calls Raw LwIP APIs that are not safe to call from other threads without locking. While some raw APIs are being called by using tcpip_api_call(), other calls are not considering this method, as [1], [2], [3], and [4].

When CONFIG_LWIP_CHECK_THREAD_SAFETY is enabled, the system gets aborted when the lwip core is not locked; Therefore exposing a source of bugs.

Any call to tcpip_api_call() in tcpip core locked results in a deadlock, thus removed the corresponding calls.

I've prefered to check against the state before locking and unlocking, helpful when any concerned AsyncUDP API being called from within LwIP thread, highly through callbacks, if any.

This will not affect the direct Arduino users but until esp32-arduino-libs-builder PR gets merged it will fix a source of bugs.

Currently: Arduino-as-ESPIDF-component users can easily have this fix by enabling CONFIG_LWIP_TCPIP_CORE_LOCKING option.

https://www.nongnu.org/lwip/2_1_x/multithreading.html

#10391 (comment)