Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash with fast ping on espressif #7938

Merged
merged 1 commit into from
May 5, 2023
Merged

Conversation

jepler
Copy link
Member

@jepler jepler commented May 5, 2023

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:

>>> while True: wifi.radio.ping(wifi.radio.ipv4_gateway)
... 
0.0
0.0
0.002
0.001
0.0
0.0
0.004
0.001
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
espidf.IDFError: Generic Failure
>>> 

Closes #5980 based on my testing on an ESP32S3-N8R2.

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.
Copy link

@kattni kattni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this on a QT Py ESP32-S2 running code including ping that was consistently resetting into safe mode, regardless of the ping delay. I can now successfully run the code without resetting into safe mode.

Thanks so much for the fix!

@kattni kattni merged commit 018f15d into adafruit:main May 5, 2023
132 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ping too frequently results in Safe Mode
2 participants