Skip to content

Commit 66411fd

Browse files
committed
espressif: check return value from esp_ping_new_session
esp_ping_new_session can fail, particularly if ping is called quickly many times in succession. This is because `esp_ping_new_session` has to do a bunch of stuff including creating a task and a socket. Calling `esp_ping_delete_session` doesn't clean up these resources immediately. Instead, it signals the task to clean up resources and exit 'soon', but 'soon' is defined as 1 second. When the calls are frequent, the in-use sockets and tasks fill up available slots—I didn't actually check which resource gets used up first. With this change, the ping call will raise an exception instead of continuing with a call to esp_ping_start that crashes. Closes adafruit#5980 based on my testing on an ESP32S3-N8R2.
1 parent bd9aca2 commit 66411fd

File tree

1 file changed

+2
-1
lines changed
  • ports/espressif/common-hal/wifi

1 file changed

+2
-1
lines changed

ports/espressif/common-hal/wifi/Radio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <string.h>
3131

32+
#include "bindings/espidf/__init__.h"
3233
#include "common-hal/wifi/__init__.h"
3334
#include "shared/runtime/interrupt_char.h"
3435
#include "py/gc.h"
@@ -497,7 +498,7 @@ mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address,
497498
size_t timeout_ms = timeout * 1000;
498499

499500
esp_ping_handle_t ping;
500-
esp_ping_new_session(&ping_config, NULL, &ping);
501+
CHECK_ESP_RESULT(esp_ping_new_session(&ping_config, NULL, &ping));
501502
esp_ping_start(ping);
502503

503504
uint32_t received = 0;

0 commit comments

Comments
 (0)