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

AP_ESC_Telem: fix other timeout race #29028

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

robertlong13
Copy link
Collaborator

Prerequisite PR: #28999

The timeout for non-RPM telemetry is vulnerable to a similar race to the RPM one above. This PR makes the timeout logic consistent between the two, adding a validity flag to track the timeout instead of explicitly subtracting timestamps (one of which is volatile).

I broke this PR into a separate dependent PR in case this is considered too risky of a change. I have an alternative PR ready, mirroring how Pete is binding AP_Servo_Telem in the soon-to-be-merged #28857. That PR would be guaranteed not to change any behavior outside of Lua, however, I think this PR is vastly a better approach.

The RPM telemetry data structure can get updated by another thread at
any time. This can cause (now - last_update_us) to be negative, which
looks like the data is nearly UINT32_MAX microseconds stale. To fix
this, we copy the last_update_us value before we get the current time
so it's guaranteed to be positive.

We also minimize the number of places we explicitly check the timestamp
and rely on the `data_valid` where possible to minimize the performance
impact of this change.
The timeout for non-RPM telemetry is vulnerable to a similar race as the
RPM. This change makes the timeout logic consistent between the two.
@robertlong13 robertlong13 requested a review from andyp1per January 9, 2025 04:47
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.

1 participant